|
@@ -6,12 +6,26 @@ use app\common\controller\Backend;
|
|
|
use app\admin\model\Template;
|
|
|
use app\admin\model\UserGroup;
|
|
|
use Exception;
|
|
|
-use think\Db;
|
|
|
use think\exception\DbException;
|
|
|
use think\exception\PDOException;
|
|
|
use think\exception\ValidateException;
|
|
|
use think\response\Json;
|
|
|
-
|
|
|
+use DateTime;
|
|
|
+use onesignal\client\api\DefaultApi;
|
|
|
+use onesignal\client\Configuration;
|
|
|
+use onesignal\client\model\GetNotificationRequestBody;
|
|
|
+use onesignal\client\model\Notification;
|
|
|
+use onesignal\client\model\StringMap;
|
|
|
+use onesignal\client\model\Player;
|
|
|
+use onesignal\client\model\UpdatePlayerTagsRequestBody;
|
|
|
+use onesignal\client\model\ExportPlayersRequestBody;
|
|
|
+use onesignal\client\model\Segment;
|
|
|
+use onesignal\client\model\FilterExpressions;
|
|
|
+use GuzzleHttp;
|
|
|
+use app\common\model\User;
|
|
|
+use think\Db;
|
|
|
+use think\Queue;
|
|
|
+use think\Request;
|
|
|
/**
|
|
|
*
|
|
|
*
|
|
@@ -31,6 +45,24 @@ class Message extends Backend
|
|
|
parent::_initialize();
|
|
|
$this->model = new \app\admin\model\Message;
|
|
|
$this->view->assign("statusList", $this->model->getStatusList());
|
|
|
+ $url = $_SERVER['HTTP_HOST'];
|
|
|
+ if (strpos($url, 'westkiss') !== false) {
|
|
|
+ $appKeyToken='MDMwZThjYWMtOWQ4ZC00YzU3LWIwNjktOGYzNTA2NjA3NTBh';
|
|
|
+ $userKeyToken='YTdmZGE5MGEtN2Y3Yi00Mzk0LTgyOGQtMGMzNDkzYTcxYmJh';
|
|
|
+ }elseif (strpos($url, 'asteriahair') !== false) {
|
|
|
+ $appKeyToken='NGU4ZTU0OGUtMGU2Yy00NjNmLTgwNWItZTVmYjQxODg5Yzhh';
|
|
|
+ $userKeyToken='NjQwYWRlYWEtODlmZS00ZDFhLThmZmMtN2E0ZTQwZWI2NmY5';
|
|
|
+ }else{
|
|
|
+ $appKeyToken='NzRhMTYyODUtYzczYi00Yjg5LWI3NzktODFmMmY0MGUyODIx';
|
|
|
+ $userKeyToken='NWU3OGMxNzgtZjEzNS00M2JmLThmNzItZjY5YzIxOWU5YTQ3';
|
|
|
+ }
|
|
|
+ $config= Configuration::getDefaultConfiguration()
|
|
|
+ ->setAppKeyToken($appKeyToken)
|
|
|
+ ->setUserKeyToken($userKeyToken);
|
|
|
+ $this->apiInstance = new DefaultApi(
|
|
|
+ new GuzzleHttp\Client(),
|
|
|
+ $config
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -216,6 +248,66 @@ class Message extends Backend
|
|
|
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
|
|
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
|
|
*/
|
|
|
+ public function test()
|
|
|
+ {
|
|
|
+ $data =input();
|
|
|
+ $id=$data['ids'];
|
|
|
+ $wheres['id']=$id;
|
|
|
+ $one_push = Db::name('message')->where($wheres)->find();
|
|
|
+ if (empty($one_push)) {
|
|
|
+ echo '没有查到推送队列';
|
|
|
+ exit;
|
|
|
+ }
|
|
|
+ $result =$this->sendTest($one_push);
|
|
|
+ $this->success();
|
|
|
+ }
|
|
|
|
|
|
+ function createNotification($one_push){
|
|
|
+ $template_dsc =$one_push['template_dsc'];
|
|
|
+ $title =$one_push['template_name'];
|
|
|
+ $type =$one_push['type'];
|
|
|
+ $url =$one_push['para'];
|
|
|
+ $content = new StringMap();
|
|
|
+ $content->setEn($template_dsc);
|
|
|
+ $notification = new Notification();
|
|
|
+ $notification->setContents($content);
|
|
|
+ $notification->setIosBadgeType('Increase');
|
|
|
+ $notification->setIosBadgeCount(1);
|
|
|
+ $notification->setIsIos(true);
|
|
|
+ $notification->setContentAvailable(true);
|
|
|
+ $data['push_para']=$url;
|
|
|
+ $data['push_type']=$type;
|
|
|
+ $data['title']=$title;
|
|
|
+ $data['message_id']=$one_push['id'];
|
|
|
+ $notification->setData($data);
|
|
|
+ $notification->setMutableContent(true);
|
|
|
+ $apns_alert['title']=$title;
|
|
|
+ $notification->setApnsAlert($apns_alert);
|
|
|
+ if($one_push['template_image']){
|
|
|
+ $request = Request::instance();
|
|
|
+ $domain=$request->domain();
|
|
|
+ $images['id'] = $domain.$one_push['template_image'];
|
|
|
+ $notification->setIosAttachments($images);
|
|
|
+ }
|
|
|
+ return $notification;
|
|
|
+ }
|
|
|
+ public function sendTest($one_push){
|
|
|
+ $appId =$this->getAppId();
|
|
|
+ $notification = $this->createNotification($one_push);
|
|
|
+ $notification->setAppId($appId);
|
|
|
+ $notification->setIncludedSegments(['TestUsers']);
|
|
|
+ return $this->apiInstance->createNotification($notification);
|
|
|
+ }
|
|
|
+ public function getAppId(){
|
|
|
+ $url = $_SERVER['HTTP_HOST'];
|
|
|
+ if (strpos($url, 'westkiss') !== false) {
|
|
|
+ $appId ='6bbd561f-4d8e-4d04-a6c4-dbef1bf99694';
|
|
|
+ }elseif (strpos($url, 'asteriahair') !== false) {
|
|
|
+ $appId ='618fe580-bc97-4bf4-b2bb-5039f9dbbc82';
|
|
|
+ }else{
|
|
|
+ $appId ='b3124d44-7bc7-4965-95dc-0ecb502fdaea';
|
|
|
+ }
|
|
|
+ return $appId;
|
|
|
+ }
|
|
|
|
|
|
}
|