php遍历手机app,uniapp 小程序获取手机号码 前端+php后台

前端

手机号一键登录

后台

query($q);

dump($res);

}

/**

* post: 用户&&商家注册或登陆

* path: register

* method: register

* param: phone - {string} 手机号

* param: type - {int} 1为用户 2为商家

* param: friend_id - {int} 用户id 分享是传入

*/

public function registerOrLogin()

{

$type = input('type');

$wxCode = input('code');

$encryptedData = input('encryptedData');

$iv = input('iv');

$appid = 'wxcd35e514f4b305ba';

$appsecret = '5a5aeafd46d487933f765f3c9f95bb9d';

$oauth2Url = "https://api.weixin.qq.com/sns/jscode2session?appid=".$appid."&secret=".$appsecret."&js_code=".$wxCode."&grant_type=authorization_code";

$result = file_get_contents($oauth2Url);

$obj = json_decode($result);

$session_key = $obj->session_key;

$openid = $obj->openid;

$unionid = $obj->unionid;

$pc = new wxBizDataCrypt($appid, $session_key);

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

if ($errCode == 0) {

$numDatas = json_decode($data);

$phone = $numDatas->phoneNumber;

$userinfo = $this->is_register($phone);

if (! $userinfo){

// 在db插入新用户

$data = [

'name' => 'U' . $phone.$type,

'nick' => 'U' . substr($phone, -4),

'headimg' => '/uploads/default/head.png',

'phone' => $phone,

'addtime' => date("Y-m-d H:i:s"),

'type' => $type,

'openid' => $openid

];

$res = db($this->user)->insertGetId($data);

if ($res){

$returnData = [

'userId' => $userinfo['id'],

'nick' => $userinfo['nick'],

'headimg' => 'http://app.51oil.net.cn'.$userinfo['headimg'],

];

$this->result($returnData, 1, '');

}

}else{

$returnData = [

'userId' => $userinfo['id'],

'nick' => $userinfo['nick'],

'headimg' => 'url'.$userinfo['headimg'],

];

$this->result($returnData, 1, '');

}

} else {

print($errCode . "\n");

}

}

/**

* post: 手机号查询用户信息

* path: is_register

* method: is_register

* param: phone - {string} 手机号

*/

public function is_register($phone)

{

if (!$phone || !is_phone($phone)) {

$this->result('', 0, '请输入正确格式的手机号码');

}

$find = db($this->user)->where('phone', $phone)->find();

return $find;

}

//https请求(支持GET和POST)

public function https_request($url, $data = null)

{

$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, $url);

//https

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);

curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);

if (!empty($data)){

curl_setopt($curl, CURLOPT_POST, 1);

curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

}

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

$output = curl_exec($curl);

curl_close($curl);

return $output;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值