|
@@ -40,9 +40,8 @@ class Login extends Base
|
|
|
* @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
|
|
|
- * @return name:openid type:string default:-- desc:用户openid
|
|
|
- * @return name:headimg type:string default:-- desc:用户头像地址
|
|
|
- * @return name:name type:string default:-- desc:用户昵称
|
|
|
+ * @param name:encrypted type:int require:0 default:0 desc:encrypted
|
|
|
+ * @param name:iv type:int require:0 default:0 desc:iv
|
|
|
* @return name:token type:string default:-- desc:用户登录成功后的token值
|
|
|
*/
|
|
|
public function weChatLogin(){
|
|
@@ -50,6 +49,8 @@ class Login extends Base
|
|
|
$headimg = input('headimg');
|
|
|
$name = input('name');
|
|
|
$pid = input('pid',0);
|
|
|
+ $iv = input('iv');
|
|
|
+ $encryptedData = input('encrypted');
|
|
|
if(empty($code) || empty($headimg) || empty($name)){
|
|
|
$this->error('参数错误');
|
|
|
}
|
|
@@ -58,6 +59,15 @@ class Login extends Base
|
|
|
if(empty($data['openid'])){
|
|
|
$this->error($data['errmsg']);
|
|
|
}
|
|
|
+
|
|
|
+ require_once env('root_path').'/vendor/program/wxBizDataCrypt.php';
|
|
|
+ $sessionKey = $data['session_key'];
|
|
|
+ $pc = new \WXBizDataCrypt(config('app.mini_program')['app_id'], $sessionKey);
|
|
|
+ $errCode = $pc->decryptData($encryptedData, $iv, $info);
|
|
|
+ if($errCode != 0) $this->error('微信登录失败');
|
|
|
+ $info = json_decode($info,true);
|
|
|
+ $phone = $info['purePhoneNumber'];
|
|
|
+
|
|
|
$member = Db::name('store_member')->field('id,phone')->where('openid',$data['openid'])->find();
|
|
|
if(empty($member)){
|
|
|
$member_data = array(
|
|
@@ -65,6 +75,7 @@ class Login extends Base
|
|
|
'headimg' => $headimg,
|
|
|
'name' => $name,
|
|
|
'pid' =>$pid,
|
|
|
+ 'phone' => $phone,
|
|
|
'create_at'=>date("Y-m-d H:i:s")
|
|
|
);
|
|
|
Db::table('store_member')->insert($member_data);
|