private function GetUserInfo() { $UserModel = new AnymagicUserModel(); $UserInfo = $UserModel->CheckUser($this->WechatOpenId, $this->WechatUnionId); if ($UserInfo !== false && $UserInfo != null) { if ($UserInfo['lasttime'] <= time()) { $JssdkModel = new JSSDKModel(); $UserInfo = $JssdkModel->getUserInfo($this->WechatOpenId); if (isset($UserInfo['errcode'])) { $UserInfo = ''; echo $UserInfo['errmsg'], '<br />'; exit; } $UpResult = $UserModel->UpdateUser($UserInfo); if ($UpResult == false) { echo 'GetUserInfo UpResult False', '<br />'; } } } else { if (!empty($this->WechatOpenId)) { $JssdkModel = new JSSDKModel(); $UserInfo = $JssdkModel->getUserInfo($this->WechatOpenId); if (isset($UserInfo['errcode'])) { $UserInfo = ''; echo $UserInfo['errmsg'], '<br />'; exit; } $AddResult = $UserModel->AddNewUser($UserInfo); if ($AddResult == false) { echo 'GetUserInfo AddResult False', '<br />'; } } else { $UserInfo = false; } } return $UserInfo; }
/** * 微信客服回复函数 */ private function wxServiceRepeat($UserId, $msg) { $wxChat = new JSSDKModel(); $Token = $wxChat->GetToken(); $UserModel = new UserModel(); $UserResult = $UserModel->GetUserInfo($UserId); $data['touser'] = $UserResult['openid']; $data['msgtype'] = 'text'; $data['text'] = array('content' => $msg); $data = $this->encode_json($data); $url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' . $Token; $header = array('Content-Type: application/json; charset=utf-8', 'Content-Length: ' . strlen($data)); $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // The maximum number of seconds to allow cURL functions to execute. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60); $response = curl_exec($ch); if (curl_errno($ch)) { return false; //return curl_errno($ch); } curl_close($ch); if (!isset($response['errcode'])) { return true; } else { return false; } }