/*
* 获取用户的电话
* wxmobile 下载地址 https://gitee.com/zzl_index/wechat-refund.git
* */
public function getmobile()
{


require_once Env::get('ROOT_PATH')."extend/wxMobile/WxBizDataCrypt.php";

$config = config('wechat.');
$appid = $config['app_id'];
$app_secret = $config['app_secret'];
$code = $this->request->param('code','');

$token = json_decode($this->getCurl("https://api.weixin.qq.com/sns/jscode2session?appid={$appid}&secret={$app_secret}&js_code={$code}&grant_type=authorization_code"), true);

$session_key = $token['session_key'];


$encryptedData = $this->request->param('encryptedData','');
$iv= $this->request->param('iv','');


$pc = new \WxBizDataCrypt($appid, $session_key);

$errCode = $pc->decryptData($encryptedData, $iv, $data );

$openid = $token['openid'];

if (!$openid){
return error('参数错误');
}
if ($errCode == 0) {
$user_model = new User();
$data = trim($data,'\"');
$data= json_decode($data);
$phone = $data->phoneNumber;
$res = $user_model->save(['mobile'=>$phone],['openid'=>$openid]);
if ($res){
$info = $user_model->where(['openid'=>$openid])->find();
return success($info,'请求成功');
}else{
return error('保存失败');
}

} else {
return error('获取电话失败');

}
}