public static function callBack($data)
{
if (!empty($data)) {
if (isset($data['MsgType']) && $data['MsgType'] == 'event') {
$userInfo = login::get_user_info($data['FromUserName']);
$userInfo = json_decode($userInfo, true);
if (stristr($data['EventKey'],'bindingPhone')){
$arr = array(
'EventKey' => $data['EventKey'],
);
if ($data['Event'] == 'SCAN') {
$res = Db::table('user')->where('wx_open_id', $data['FromUserName'])->update($arr);
if ($res !== false) {
login::replacePhone($data);
return true;
}
}
}
if (stristr($data['EventKey'],'unbindPhone')){
$arr = array(
'EventKey' => $data['EventKey'],
'phone'=>'',
'password'=>''
);
if ($data['Event'] == 'SCAN') {
$res = Db::table('user')->where('wx_open_id', $data['FromUserName'])->update($arr);
if ($res !== false) {
login::unbindPhone($data);
return true;
}
}
}
$textTpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>
<Content><![CDATA[%s]]></Content>
</xml>";
if ($data['Event'] == 'subscribe') {
$str = '提示訊息';
$time = time();
$resultStrq = sprintf($textTpl, $data['FromUserName'], 'czh_sjpt', $time, 'text', $str);
echo $resultStrq;
}
if ($data['Event'] == 'SCAN') {
$str = '登入成功';
$time = time();
$resultStrq = sprintf($textTpl, $data['FromUserName'], 'czh_sjpt', $time, 'text', $str);
echo $resultStrq;
}
$arr = array(
'EventKey' => $data['EventKey'],
'event' => $data['Event'],
'head_portrait' => $userInfo['headimgurl'],
'nickname' => login::filterEmoji($userInfo['nickname']),
'wx_open_id' => $data['FromUserName'],
);
return true;
}
}
}
public static function get_user_info($openId){
$accessToken = login::get_access_token();
$url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=".$accessToken."&openid=".$openId."&lang=zh_CN";
$data = login::httpRequest($url);
return $data;
}
~~~
本作品採用《CC 協議》,轉載必須註明作者和本文連結