原因,发送消息encode的时候没有添加JSON_UNESCAPED_UNICODE
重点代码:
$result = $this->httpPost($url, json_encode($data, JSON_UNESCAPED_UNICODE));
原始写法:
$result = $this->httpPost($url, json_encode($data));
最终代码
public function sendLoginAlert($admin_id){$allow_send = BuyerConfig::where(['admin_id' => $admin_id])->value("mp_notice", 0);if (!$allow_send){return false;}$admin_info = $this->getAdminInfo($admin_id);if (!$admin_info){return false;}$url = 'https://api./cgi-bin/message/custom/send?access_token='.$this->getAccessToken();$data = ['touser' => $admin_info['openid'],'msgtype' => "text",'text' => ['content' => "欢迎【{$admin_info['nickname']}】登录成功!"]];$result = $this->httpPost($url, json_encode($data, JSON_UNESCAPED_UNICODE));if (isset($result['errcode']) && $result['errcode'] != 0){// 记录发送失败日志file_put_contents("login.log", $admin_info['nickname'].'登录失败'.PHP_EOL.PHP_EOL, FILE_APPEND);}else{file_put_contents("login.log", $admin_info['nickname'].'登录成功'.PHP_EOL.PHP_EOL, FILE_APPEND);}return $result;}