微信企业号发消息php代码及 {"errcode":82001,"errmsg":"All touser & toparty & totag invalid"}错误

{“errcode”:82001,”errmsg”:”All touser & toparty & totag invalid”}错误一般是因为权限不够,无法使用通讯录,需要去企业号添加。

$data = $user->where("id='$fromid'")->find();
$fromname = $data["name"];
$fromid = $data["jobid"];
$data = $user->where("id='$toid'")->find();
$toname = $data["name"];
$toid = $data["jobid"];
$weixin = new \Org\Util\weixin();
$access_token = $weixin->refreshAccessToken();
$sendMsg = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$access_token";

$ftmp = '{
       "touser": "'.$toid.'",
       "toparty": "",  //参数可选
       "totag": "",    //参数可选
       "msgtype": "text",
       "agentid": 9,    //注意(corpID,secret)和应用必须有相关通讯录权限
       "text": {
           "content": "恭喜您,获得来自'.$fromname.'的'.$count.'积分,原因:'.$remark.'"
       },
       "safe":0
    }';

$ttmp = '{
       "touser": "'.$fromid.'",
       "toparty": "",
       "totag": "",
       "msgtype": "text",
       "agentid": 9,
       "text": {
           "content": "积分变动:发放给'.$toname.'积分'.$count.',原因:'.$remark.'"
       },
       "safe":0
    }';

$this->https_request($sendMsg,$ftmp);
$this->https_request($sendMsg,$ttmp);

注意微信发送带中文信息时,如果你用json_encode()话要经过简单处理。我这里使用的是拼凑json字符串。
微信接收json数据提示invalid charset. please check your request, if include \uxxxx will create fail!

你可能感兴趣的:(api,php)