diff --git a/app/api/controller/Wechat.php b/app/api/controller/Wechat.php new file mode 100644 index 0000000..9780b74 --- /dev/null +++ b/app/api/controller/Wechat.php @@ -0,0 +1,22 @@ +notify(new RecordModel,'','add'); + } +} diff --git a/extend/hema/wechat/Index.php b/extend/hema/wechat/Index.php new file mode 100644 index 0000000..8cf6562 --- /dev/null +++ b/extend/hema/wechat/Index.php @@ -0,0 +1,89 @@ +config = $value; + + } + + + public function index() + { + + //接收微信推送数据 + $nonce = empty ( $_GET ['nonce'] ) ?"" : trim ( $_GET ['nonce'] ); + $signature = empty ( $_GET['signature'] ) ? "" : trim ( $_GET ['signature'] ); + $timeStamp = empty ( $_GET ['timestamp']) ? "" : trim ( $_GET ['timestamp'] ); + $msg_signature = empty ( $_GET['msg_signature'] ) ? "" : trim ( $_GET ['msg_signature'] ); + $encryptMsg = file_get_contents ('php://input' ); + $pc = new WxBizMsgCrypt();//创建解密类 + $msg = ''; + $errCode = $pc->decryptMsg($msg_signature, $timeStamp, $nonce, $encryptMsg, $msg); + if($errCode == 0){ + $data = _xml_to_arr($msg); //XML转换为数组 + + //首次关注公众号 + if($data['MsgType']=='event'){ + if($data['Event']=='subscribe'){ + $wx = new Driver; + if($wechat_user = $wx->getWechatUserInfo($data['FromUserName'],10001)){ + //用户操作 + $model = new UserModel; + if($user = $model->subscribe($wechat_user,$this->wechat['applet_id'])){ + if($this->wechat['applet_id'] == 0){ + $wx->sendServiceMsg([ + 'type' => 'text', + 'content' => '请妥善保管您的账号和密码~账号:' . $user['user_name'] . ',密码:' .$user['password'] . ',如忘记回复“找回账号”找回~' + ],$data['FromUserName'],$this->wechat['applet_id']); + } + } + if(isset($data['Ticket']) and $data['EventKey'] == 'qrscene_login'){ + //扫码关注公众号 + Cache::set($data['Ticket'],$wechat_user,3600); + } + }else{ + //返回文本提醒 + $wx->sendServiceMsg([ + 'type' => 'text', + 'content' => $wx->getError() + ],$data['FromUserName'],$this->wechat['applet_id']); + } + //是否设置了关注回复 + if($subscribe = SettingModel::getItem('subscribe',$this->wechat['applet_id'])){ + $this->replyMsg($subscribe,$data);//回复信息 + } + die('success'); + } + + } + + + } + + + + + } + + + +} \ No newline at end of file diff --git a/runtime/session/sess_31e79552bdc9d8bfd196f0495656145c b/runtime/session/sess_31e79552bdc9d8bfd196f0495656145c deleted file mode 100755 index 9597f34..0000000 Binary files a/runtime/session/sess_31e79552bdc9d8bfd196f0495656145c and /dev/null differ