...
|
...
|
@@ -2,8 +2,10 @@ |
|
|
|
|
|
namespace app\api\controller;
|
|
|
|
|
|
use EasyWeChat\Foundation\Application;
|
|
|
use think\Db;
|
|
|
use app\common\controller\Api;
|
|
|
use think\Request;
|
|
|
|
|
|
/**
|
|
|
* 用户接口
|
...
|
...
|
@@ -148,26 +150,44 @@ class User extends Api |
|
|
|
|
|
|
|
|
/**
|
|
|
* 用户接口
|
|
|
* @ApiTitle (绑定手机号)
|
|
|
* @ApiSummary (绑定手机号)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/User/BindMobile)
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
* @ApiParams (name="mobile", type="integer", required=true, description="手机号")
|
|
|
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
|
|
* @ApiParams (name="vi", type="string", required=true, description="vi")
|
|
|
* @ApiParams (name="encryptData", type="string", required=true, description="encryptData")
|
|
|
* @ApiParams (name="code", type="string", required=true, description="code")
|
|
|
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
|
|
* @ApiReturn ({
|
|
|
'code':'1',
|
|
|
'msg':'返回成功',
|
|
|
'data':{
|
|
|
})
|
|
|
*/
|
|
|
public function BindMobile()
|
|
|
{
|
|
|
$UserId = $this->IsToken($this->request->header());
|
|
|
$Mobile = input('mobile');
|
|
|
$params = Request::instance()->post(false);
|
|
|
$options = [
|
|
|
// ...
|
|
|
'mini_program' => [
|
|
|
|
|
|
'app_id' => 'wx6a9080f20326f817',
|
|
|
'secret' => '8fe9780e13dd1fa64b886c4f716cd366',
|
|
|
'token' => 'component-token',
|
|
|
'aes_key' => 'component-aes-key'
|
|
|
],
|
|
|
// ...
|
|
|
];
|
|
|
$app = new Application($options);
|
|
|
$miniProgram = $app->mini_program;
|
|
|
$sessionKey = $miniProgram->sns->getSessionKey($params['code']);
|
|
|
$Json = $miniProgram->encryptor->decryptData($sessionKey['session_key'], urldecode($params['iv']), urldecode($params['encryptData']));
|
|
|
$Mobile = $Json['phoneNumber'];
|
|
|
$Res = Db::name('user')->where('id', $UserId)->update(['mobile' => $Mobile, 'updatetime' => time()]);
|
|
|
if ($Res) $this->success('绑定成功', 1);
|
|
|
else $this->error('绑定失败', 0);
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|