作者 李忠强

更新

... ... @@ -129,6 +129,35 @@ class User extends Api
}
}
/**
* 获取微信手机号
*
* @ApiMethod (POST)
* @param string $token token
* @param string $code Code码
*/
public function thirdMobile()
{
$code = $this->request->post('code');
if (!$code){
$this->error('后台所需参数缺失请完善参数');
}
$token = $this->getToken();
$param = [];
$param['access_token'] = $token;
$param['code'] = $code;
$wxapi = Http::post('https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token='.$token,$param);//请求openid
$wxapi = json_decode($wxapi,true);
if ($wxapi['errcode'] != 0){
$this->error($wxapi['errmsg']);
}
$mobile = $wxapi['phone_info']['purePhoneNumber'];
$user = $this->auth->getUser();
$user->mobile = $mobile;
$user->isUpdate()->save();
}
/**
* @ApiTitle (用户优惠券)
* @ApiMethod (POST)
... ...
... ... @@ -3,6 +3,7 @@
namespace app\common\controller;
use app\common\library\Auth;
use fast\Http;
use think\Config;
use think\Db;
use think\exception\HttpResponseException;
... ... @@ -403,4 +404,19 @@ class Api
}
return $sum_price;
}
/**
* 获取微信token
*/
protected function getToken()
{
$param = [
'grant_type' => 'client_credential',
'appid' => Config::get('site.appid'),
'secret' => Config::get('site.secret')
];
$http = Http::get('https://api.weixin.qq.com/cgi-bin/token',$param);
$http = json_decode($http,true);
return $http['access_token'];
}
}
... ...