Mike 7 år sedan
förälder
incheckning
9206229246

+ 2 - 2
miaomiao/www/js/app.js

xqd
@@ -51,10 +51,10 @@
                }
                var receiveNotification = function (event) {
                    $rootScope.$emit('msg-new', { msg: '有新消息' });
-                   // alert("receiveMessageIniOSCallback是" + +JSON.stringify(event));
+                   alert("receiveMessageIniOSCallback是" + +JSON.stringify(event));
                };
                var setTagsWithAliasCallback = function (event) {
-                   // window.alert('result code:' + event.resultCode + ' tags:' + event.tags + ' alias:' + event.alias);
+                   window.alert('result code:' + event.resultCode + ' tags:' + event.tags + ' alias:' + event.alias);
                };
                if (window.cordova) {
                    jpushService.init({

+ 20 - 0
miaomiao/www/js/services/jpushservice.js

xqd
@@ -39,6 +39,26 @@
                     $state.go('app.home_dreamdetail',{id: id, type: 3});
                 }
 
+            }
+            window.plugins.jPushPlugin.openNotificationInIosCallback = function(res){
+                alert(res):
+                var obj = JSON.parse(res);
+                console.log(obj);
+                var id = obj.extras['id'].id;
+                var type = obj.extras['type'].type;
+                if(type == 1){
+                    $state.go('app.home_dreamdetail',{id: id, type: 1});
+                }
+                else if(type == 2){
+                    $state.go('app.home_dreamdetail',{id: id, type: 2});
+                }
+                else if(type == 3){
+                    $state.go('app.letterDetail');
+                }
+                else if(type == 4){
+                    $state.go('app.home_dreamdetail',{id: id, type: 3});
+                }
+
             }
             //前台收到推送
             document.addEventListener("jpush.receiveNotification", config.notify, false);

+ 20 - 2
server/app/Helper/JpushHelper.php

xqd xqd
@@ -3,15 +3,15 @@ namespace App\Helper;
 
 use JPush\Client as JPush;
 use App\Models\UserInfoModel;
-use App\User;
 
 trait JpushHelper
 {
-    public function jPush($title,$content='',$userid=0) {
+    public function jPush($title,$content='',$userid=0,$type=0,$id=0) {
         $app_key = '69838317211448192366f9d8';
         $master_secret = 'f202d10301151e1816b49e55';
         $client = new JPush($app_key, $master_secret, storage_path('logs/jpush.log'));
 
+        \Log::info('jpush start!');
 //        $push = new Push;
 //        $push->title = $title;
 //        $push->content = $content;
@@ -30,6 +30,24 @@ trait JpushHelper
                 $pusher->setPlatform(['ios', 'android']);
 //                $pusher->addAllAudience();
                 $pusher->addRegistrationId($regId);
+                if($type!=0&&$id!=0){
+                    $pusher->androidNotification($title,[
+                        'title' => $content,
+                        'content_type' => 'text',
+                        'extras' => [
+                            'type' => 1,
+                            'id' => 2,
+                        ]
+                    ]);
+                    $pusher->iosNotification($title, [
+                        'sound' => 'sound',
+                        'badge' => '+1',
+                        'extras' => [
+                            'type' => 1,
+                            'id' => 2,
+                        ]
+                    ]);
+                }
                 $pusher->setNotificationAlert($title);
                 $pusher->options($options);
                 $pusher->send();

+ 2 - 0
server/app/Http/Controllers/Api/V1/AuthController.php

xqd
@@ -23,12 +23,14 @@ class AuthController extends Controller
 
     public function test(){
         //test
+        $this->jPush("title",'content',77,2,452);
         if(env("APP_DEBUG")){
             return $this->error(0);
         }else{
         //product
             return $this->api(1);
         }
+
     }
 
     public function info(Request $request){