isPost()) { $data = $this->request->post(); $isBind= Db::name('oauth_log')->where('user_id',$data['id'])->value('opid_status'); if ($isBind) { $this->success(('succeeded!'), ['isBind' => 'ture',]); }else { $this->success(('succeeded!'), ['isBind' => 'falase',]); } } } /** * 公众号服务器推送 * @param Request $request * @author jsjxsz */ public function messageServe(Request $request) { try { $params = $request->param(['signature', 'timestamp', 'nonce', 'echostr']); if (isset($params['echostr']) && !empty($params['echostr'])) { $res = MessageService::getInstance()->checkSignature($params); if ($res !== false) { echo $params['echostr']; } else { echo '验证失败'; } exit(); } return MessageService::getInstance()->messageServe(); } catch (ValidateException|PDOException $e) { $this->error($e->getMessage()); } } /** * 微信公众号网页授权绑定uuid * @throws \Exception */ public function oauth(Request $request) { $code = $request->param('code'); if (!isset($code)) { try { $redirectUrl = OaService::getInstance()->getRedirectUrl(); header("Location: {$redirectUrl}"); exit(); } catch (\Exception $e) { $this->error($e->getMessage()); } } $result = OaService::getInstance()->oauthCallback($code); // header("Content-Type: application/json"); if (!isset($result['openid'])) { $this->error('获取openid失败'); throw new \Exception('获取openid失败'); } } /** * 仪器预约待审核通知 * @param Request $request * @return void * @throws \Exception */ public function sendAuditMessage(Request $request): void { if ($request->isPost()) { $res = $this->request->post(); $openid = $res["openid"]; $template_id = 'xsYnur6koCvgu1nUQwHmu8DX5SoL06P_nYMyK_oThGU'; $data = [ 'character_string7' => ['value' => $res["data"]["character_string7"]], 'thing4' => ['value' => $res["data"]["thing4"]], 'const6' => ['value' => $res["data"]["const6"]], 'time9' => ['value' => date('Y-m-d H:i')], ]; $url = 'http://weixin.qq.com/download'; $miniprogram = [ 'appid' => 'wx58633590ab59b7a1', 'pagepath' => '' ]; $result = OaService::getInstance()->sendTemplateMessage($openid, $template_id, $data,$url, $miniprogram); if ($result !== false) { $this->success('发送成功'); } else { $this->error('发送失败'); } } } /** * 仪器预约待审核通知 * @param * @return void * @throws \Exception */ public function wxAuditMessage($res = null): void { $openid = $res["openid"]; $template_id = 'xsYnur6koCvgu1nUQwHmu8DX5SoL06P_nYMyK_oThGU'; $data = [ 'character_string7' => ['value' => $res["data"]["character_string7"]], 'thing4' => ['value' => $res["data"]["thing4"]], 'const6' => ['value' => $res["data"]["const6"]], 'time9' => ['value' => date('Y-m-d H:i')], ]; $url = 'http://weixin.qq.com/download'; $miniprogram = [ 'appid' => 'wx58633590ab59b7a1', 'pagepath' => '' ]; $result = OaService::getInstance()->sendTemplateMessage($openid, $template_id, $data,$url, $miniprogram); if ($result !== false) { $this->success('发送成功'); } else { $this->error('发送失败'); } } /** * 仪器预约审核结果通知 * @param * @return void * @throws \Exception */ public function wxResultMessage($res): void { $openid = $res["openid"]; // halt($res); $template_id = 'Fxd6WNSNPbxEzQ35mDCcjzJBZClv1F9L7jWCcZmAlRI'; $data = [ 'character_string1' => ['value' => $res["data"]["character_string1"]], 'const3' => ['value' => $res["data"]["const3"]], 'const4' => ['value' => $res["data"]["const4"]], 'thing5' => ['value' => $res["data"]["thing5"]], // 'time9' => ['value' => date('Y-m-d H:i')], ]; $url = 'http://weixin.qq.com/download'; $miniprogram = [ 'appid' => 'wx58633590ab59b7a1', 'pagepath' => '' ]; $result = OaService::getInstance()->sendTemplateMessage($openid, $template_id, $data, $url, $miniprogram); if ($result !== false) { $this->success('发送成功'); } else { $this->error('发送失败'); } } /** * 仪器预约审核结果通知 * @param Request $request * @return void * @throws \Exception */ public function sendResultMessage(Request $request): void { if ($request->isPost()) { $res = $this->request->post(); $openid = $res["openid"]; // halt($res); $template_id = 'Fxd6WNSNPbxEzQ35mDCcjzJBZClv1F9L7jWCcZmAlRI'; $data = [ 'character_string1' => ['value' => $res["data"]["character_string1"]], 'const3' => ['value' => $res["data"]["const3"]], 'const4' => ['value' => $res["data"]["const4"]], 'thing5' => ['value' => $res["data"]["thing5"]], // 'time9' => ['value' => date('Y-m-d H:i')], ]; $url = 'http://weixin.qq.com/download'; $miniprogram = [ 'appid' => 'wx58633590ab59b7a1', 'pagepath' => '' ]; $result = OaService::getInstance()->sendTemplateMessage($openid, $template_id, $data, $url, $miniprogram); if ($result !== false) { $this->success('发送成功'); } else { $this->error('发送失败'); } } } }