public function DyPhone () {
$code = $this->request->param('code');
$iv = $this->request->param('iv');
$encryptedData = $this->request->param( 'encryptedData');
$doutiao = systemConfig(['toutiao_site_url', 'toutiao_appId', 'toutiao_appsecret']);
$arr = [
'appid' => $doutiao['toutiao_appId'],
'secret' => $doutiao['toutiao_appsecret'],
'code' => $code,
'anonymous_code' => "",
];
$ttapi = 'https://developer.toutiao.com/api/apps/v2/jscode2session?appid='.$arr['appid'].'&secret='.$arr['secret'].'&code='.$code;
$in = self::resCurl ($ttapi);
$in = json_decode($in,true);
$session_key= $in['session_key'];
$openid = $in['openid'];
//解密手机号
$phoneInfo = openssl_decrypt(base64_decode($encryptedData,true), 'AES-128-CBC', base64_decode($session_key), OPENSSL_RAW_DATA, base64_decode($iv));
if(!$phoneInfo){
return app('json')->fail('绑定失败');
}else{
$phone = json_decode($phoneInfo,true)['phoneNumber'];
}
$user = $this->repository->accountByUser($data['purePhoneNumber']);
if ($user) {
$data = ['phone' => $data['purePhoneNumber']];
} else {
$data = ['account' => $data['purePhoneNumber'], 'phone' => $data['purePhoneNumber']];
}
// 查询当前用户是否已存在账号如果存在切换到之前的账号 并且绑定当前微信账号
// $userPhone = Db::name('user')->where(array('phone'=>$data['purePhoneNumber']))->selectAll()->toArray();
// if ($userPhone) {
// // 如果账号多移除没有绑定电话的账号 绑定当前微信 切换账号
// $wechtData = ['wechat_user_id'=> $userPhone->wechat_user_id];
// $this->repository->update($userPhone->uid, $wechtData);
// $data['status'] = 0;
// }
$this->repository->update($this->request->uid(), $data);
// 切换用户
// $this->switchUser($userPhone->uid);
return app('json')->success('绑定成功');
}
抖音小程序授权 保存信息 php方法
最新推荐文章于 2024-08-06 16:51:47 发布