getVerifyTicket($xmlData); echo 'success'; } /** * @notes:授权回调 * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException * @author: wanghousheng */ public function redirect() { $authorization_code = $this->request->get('auth_code'); if ($authorization_code) { $obj = new \app\common\library\wxserver\Server(); $obj->authorizationInfo($authorization_code); } echo 'success'; } public function callback($appid) { $time = date('Y-m-d H:i:s'); Db::table('yoshop_wx_server')->insertGetId(['content' => '推送开始', 'created_at' => $time]); $obj = new \app\common\library\wxserver\Server(); $signature = $this->request->get('signature'); $timestamp = $this->request->get('timestamp'); $nonce = $this->request->get('nonce'); if ($signature && $timestamp && $nonce) { if ($obj->checkSignature($signature, $timestamp, $nonce)) { Db::table('yoshop_wx_server')->insertGetId(['content' => '签名正确', 'created_at' => $time]); } } $xmlData = file_get_contents("php://input"); if ($xmlData) { Db::table('yoshop_wx_server')->insertGetId(['content' => $xmlData, 'created_at' => $time]); $data = $obj->decryptXml($xmlData); Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($data), 'created_at' => $time]); if (!empty($data['MsgType'])) { if ($data['MsgType'] == 'event' && !empty($data['Event'])) { $up = []; if ($data['Event'] == 'weapp_audit_success') { $up['audit_status'] = 2; } elseif ($data['Event'] == 'weapp_audit_fail') { $up['audit_status'] = 3; } elseif ($data['Event'] == 'weapp_audit_delay') { $up['audit_status'] = 4; } if (!empty($data['Reason'])) { $up['audit_reason'] = $data['Reason']; } if ($up && $appid) { $model = new WxserverAccount(); $model->update($up, ['appid' => $appid]); } echo 'success'; } elseif ($data['MsgType'] == 'text') { echo $this->responseText($data); } } } } private function responseText($data): string { $template = " %s "; $fromUser = $data['ToUserName']; $toUser = $data['FromUserName']; $content = !empty($data['Content']) ? $data['Content'] : '收到你的信息了'; $time = time(); $msgType = 'text'; return sprintf($template, $toUser, $fromUser, $time, $msgType, $content); } }