wupengfei hace 3 años
padre
commit
a74a16887c

+ 17 - 20
application/api/controller/Login.php

@@ -37,33 +37,25 @@ class Login extends Base
      * @method POST
      * @tag 登录 授权
      * @param name:code type:int require:1 default:-- desc:code值
-     * @param name:headimg type:string require:1 default:-- desc:头像地址
-     * @param name:name type:string require:1 default:-- desc:昵称
      * @param name:pid type:int require:0 default:0 desc:推荐人id
      * @param name:goods_id type:int require:0 default:0 desc:商品id
      * @return name:token type:string default:-- desc:用户登录成功后的token值
      */
-    public function weChatLogin()
-    {
+    public function weChatLogin(){
         $code = input('code');
-        $headimg = input('headimg');
-        $name = input('name');
-        $pid = input('pid', 0);
-        $goods_id = input('goods_id', 0);
-        if (empty($code) || empty($headimg) || empty($name)) {
-            $this->error('参数错误');
-        }
-        $app = Factory::miniProgram(config('app.mini_program'));
-        $data = $app->auth->session($code);
-        if (empty($data['openid'])) {
-            $this->error($data['errmsg']);
-        }
-        $member = Db::name('store_member')->field('id,phone')->where('openid', $data['openid'])->find();
+        $pid = input('pid');
+        $goods_id = input('goods_id');
+        if(empty($code)) $this->error('参数错误');
+        $res = http_get('https://api.weixin.qq.com/sns/oauth2/access_token?appid='.config('app.official_account')['appid'].'&secret='.config('app.official_account')['secret'].'&code='.$code.'&grant_type=authorization_code');
+        $res = json_decode($res,true);
+        $member = Db::name('store_member')->field('id,phone')->where('openid', $res['openid'])->find();
         if (empty($member)) {
+            $user_info = http_get('https://api.weixin.qq.com/sns/userinfo?access_token='.$res['access_token'].'&openid='.$res['openid']);
+            $user_info = json_decode($user_info,true);
             $member_data = array(
-                'openid' => $data['openid'],
-                'headimg' => $headimg,
-                'name' => $name,
+                'openid' => $user_info['openid'],
+                'headimg' => $user_info['headimgurl'],
+                'name' => $user_info['nickname'],
                 'pid' => $pid,
                 'create_at' => date("Y-m-d H:i:s")
             );
@@ -184,4 +176,9 @@ class Login extends Base
         }
         $this->success('登录成功',['token'=>self::create_jwt($uid)]);
     }
+
+
+
+
+
 }

+ 19 - 3
config/app.php

@@ -32,11 +32,27 @@ return [
         'aes_key' => env('WECHAT_MINI_PROGRAM_AES_KEY', ''),
     ],
     'wx_pay'=>[
-        'app_id'=>'wx747acc10bf45d80d',//微信appid
-        'mch_id'=>'1619281582',//商户号
-        'key'   =>'uYirmQz6YksIXrIl4bzjSGTU0ChjrEL5',//秘钥
+        'app_id'=>'wxd95c7581bdc2d102',//微信appid
+        'mch_id'=>'1623872697',//商户号
+        'key'   =>'BqHXesgP6GHzBmaNWlJShkSsPh2FqgpO',//秘钥
         'cert_path'=>'wx_cert/apiclient_cert.pem', //证书地址
         'key_path' =>'wx_cert/apiclient_key.pem', //证书地址
     ],
+    'official_account' => [
+        // AppID
+        'appid' => env('WECHAT_OFFICIAL_ACCOUNT_APPID', 'wxd95c7581bdc2d102'),
+        // AppSecret
+        'secret' => env('WECHAT_OFFICIAL_ACCOUNT_SECRET', '886a89d0e92c38afcce0908006570f9f'),
+        // Token
+        'token' => env('WECHAT_OFFICIAL_ACCOUNT_TOKEN', 'your-token'),
+        // EncodingAESKey
+        'aes_key' => env('WECHAT_OFFICIAL_ACCOUNT_AES_KEY', ''),
+
+        'oauth' => [
+            'scopes'   => array_map('trim',
+                explode(',', env('WECHAT_OFFICIAL_ACCOUNT_OAUTH_SCOPES', 'snsapi_userinfo'))),
+            'callback' => env('WECHAT_OFFICIAL_ACCOUNT_OAUTH_CALLBACK', ''),
+        ],
+    ]
 
 ];

BIN
public/wx_cert/apiclient_cert.p12


+ 19 - 20
public/wx_cert/apiclient_cert.pem

@@ -1,24 +1,23 @@
 -----BEGIN CERTIFICATE-----
-MIID8DCCAtigAwIBAgIUMLoCY9Zdl9r0pTD6keR24yKNL8cwDQYJKoZIhvcNAQEL
+MIID7DCCAtSgAwIBAgIUXBinHuhkMfXleuuFHI9T3IaHjuswDQYJKoZIhvcNAQEL
 BQAwXjELMAkGA1UEBhMCQ04xEzARBgNVBAoTClRlbnBheS5jb20xHTAbBgNVBAsT
 FFRlbnBheS5jb20gQ0EgQ2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