xiaogang hace 4 años
padre
commit
bbcf546fe0
Se han modificado 4 ficheros con 20 adiciones y 12 borrados
  1. 11 0
      app/Http/Controllers/Api/TestController.php
  2. 7 12
      app/Services/JPushService.php
  3. 1 0
      config/jpush.php
  4. 1 0
      routes/api.php

+ 11 - 0
app/Http/Controllers/Api/TestController.php

xqd
@@ -106,4 +106,15 @@ class TestController
         }
         return response()->json(['data'=>$res]);
     }
+
+    public function jg_auth(){
+        $token="asdasd";
+        $exId="111111";
+         $ret = JPushService::jgLoginTokenVerify($token,$exId);
+         dd($ret);
+
+         $res = JPushService::jgOpensslPrivateDecrypt($ret['phone']);
+
+
+    }
 }

+ 7 - 12
app/Services/JPushService.php

xqd xqd xqd xqd xqd
@@ -16,6 +16,7 @@ class JPushService
     const PUSH_TYPE_TAG = 2;
     const PUSH_TYPE_ALIAS = 3;
     const PUSH_TYPE_REG_ID = 4;
+    const JG_YJDL_POST_URL = 'https://api.verification.jpush.cn/v1/web/loginTokenVerify';
 
     private function __construct()
     {
@@ -193,12 +194,12 @@ class JPushService
      *  err:错误信息
      *
      */
-    public function jgOpensslPrivateDecrypt($encrypted){
+    public static function jgOpensslPrivateDecrypt($encrypted){
         $prefix = '-----BEGIN RSA PRIVATE KEY-----';
         $suffix = '-----END RSA PRIVATE KEY-----';
         $result = '';
 
-        $prikey = JG_YJDL_PRIVATE_RSA;
+        $prikey = config('jpush.jg_yjdl_private_rsa');
 
         $key = $prefix . "\n" . $prikey . "\n" . $suffix;//拼接换行符
         $r = openssl_private_decrypt(base64_decode($encrypted), $result, openssl_pkey_get_private($key));
@@ -219,13 +220,13 @@ class JPushService
      *  err:错误信息
      *
      */
-    public function jgLoginTokenVerify($token,$exId)
+    public static function jgLoginTokenVerify($token,$exId)
     {
-        $host    = JG_YJDL_POST_URL;
+        $host    =  self::JG_YJDL_POST_URL;
         $method  = "POST";
-        $appcode = VERIFY_APPCODE;
+//        $appcode = VERIFY_APPCODE;
         $headers = array();
-        array_push($headers, "Authorization: Basic " .base64_encode(JG_APPKEY.':'.JG_MASTERSECRET));
+        array_push($headers, "Authorization: Basic " .base64_encode(config('jpush.app_key').':'.config('jpush.master_secret')));
         //根据API的要求,定义相对应的Content-Type
         array_push($headers, "Content-Type".":"."application/json");
 
@@ -246,11 +247,7 @@ class JPushService
         $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
 
         // file_put_contents(PATH_USER_JG_LOGIN_LOG.date('Y-m-d').'.log', date('Y-m-d H:i:s').$ret.PHP_EOL,FILE_APPEND);//写入文件 常量需要自己在定义
-
         $ret  = json_decode($ret,true);
-
-
-
         if ($ret['code'] == 8000) {
             if($ret['exID']!=$exId){
                 $ret['err'] = 'exID 返回与发送不一致';
@@ -259,8 +256,6 @@ class JPushService
         } else {
             $ret['err'] = $ret['code'].':'.$ret['content'];
         }
-
-
         return $ret;
 
 

+ 1 - 0
config/jpush.php

xqd
@@ -4,4 +4,5 @@ return [
     'app_key' => env('JPUSH_APP_KEY', ''),
     'master_secret' => env('JPUSH_MASTER_SECRET', ''),
     'apns_production' => env('JPUSH_APNS_PRODUCTION', true),
+    'jg_yjdl_private_rsa' => env('JG_YJDL_PRIVATE_RSA', true),
 ];

+ 1 - 0
routes/api.php

xqd
@@ -189,6 +189,7 @@ $api->version('v1', [
     $api->any('/creat_user', 'TestController@creat_user')->name('creat_user');
     $api->any('/create_dynamic', 'TestController@create_dynamic')->name('create_dynamic');
     $api->any('/test_push', 'TestController@test_push')->name('test_push');
+    $api->any('/jg_auth', 'TestController@jg_auth')->name('jg_auth');
 
 
 });