作者 王智

'绑定手机号'

... ... @@ -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);
}
}
... ...
... ... @@ -9303,10 +9303,22 @@
</thead>
<tbody>
<tr>
<td>mobile</td>
<td>integer</td>
<td>vi</td>
<td>string</td>
<td></td>
<td>手机号</td>
<td>vi</td>
</tr>
<tr>
<td>encryptData</td>
<td>string</td>
<td></td>
<td>encryptData</td>
</tr>
<tr>
<td>code</td>
<td>string</td>
<td></td>
<td>code</td>
</tr>
</tbody>
</table>
... ... @@ -9338,8 +9350,16 @@
<div class="panel-body">
<form enctype="application/x-www-form-urlencoded" role="form" action="/api/User/BindMobile" method="POST" name="form55" id="form55">
<div class="form-group">
<label class="control-label" for="mobile">mobile</label>
<input type="integer" class="form-control input-sm" id="mobile" required placeholder="手机号" name="mobile">
<label class="control-label" for="vi">vi</label>
<input type="string" class="form-control input-sm" id="vi" required placeholder="vi" name="vi">
</div>
<div class="form-group">
<label class="control-label" for="encryptData">encryptData</label>
<input type="string" class="form-control input-sm" id="encryptData" required placeholder="encryptData" name="encryptData">
</div>
<div class="form-group">
<label class="control-label" for="code">code</label>
<input type="string" class="form-control input-sm" id="code" required placeholder="code" name="code">
</div>
<div class="form-group">
<button type="submit" class="btn btn-success send" rel="55">提交</button>
... ... @@ -9372,11 +9392,6 @@
</thead>
<tbody>
<tr>
<td>code</td>
<td>integer</td>
<td></td>
</tr>
<tr>
<td>msg</td>
<td>string</td>
<td></td>
... ... @@ -9395,7 +9410,6 @@
<pre id="sample_response55">{
'code':'1',
'msg':'返回成功',
'data':{
}</pre>
</div>
</div>
... ... @@ -9411,7 +9425,7 @@
<div class="row mt0 footer">
<div class="col-md-6" align="left">
Generated on 2021-04-27 18:14:36 </div>
Generated on 2021-05-06 11:10:55 </div>
<div class="col-md-6" align="right">
<a href="./" target="_blank">KCD</a>
</div>
... ...