关于发送微信客服消息报44004错误的解决办法

错误如下:

{"errcode":44004,"errmsg":"empty content hint: [xCzlfa0209ge25]"} 

发送的代码如下:

def POST(self):
        data = web.data()
        reg = '''<xml><ToUserName><!\[CDATA\[(.*?)\]\]></ToUserName>'''
        reg2 = '<FromUserName><!\[CDATA\[(.*?)\]\]></FromUserName>'
        reg3 = '<CreateTime>(\d+)</CreateTime>'
        reg4 = '<MsgType><!\[CDATA\[(.*?)\]\]></MsgType>'
        reg5 = '<Content><!\[CDATA\[(.*?)\]\]></Content>'
        reg6 = '<MsgId>(\d+)</MsgId>'
        fromusers = re.compile(reg2).findall(data)[0]
        MsgType = re.compile(reg4).findall(data)[0]
        Content = re.compile(reg5).findall(data)[0]
        username, city = self.get_userinfo(fromusers)
        if fromusers != 'owV3nvshcqIgwflEMlikiXdwaP7M':
            self.leandbs.save_userinfo(fromusers)
            dic = {"touser":"owV3nvshcqIgwflEMlikiXdwaP7M","msgtype":"text","text":{"content":'【%s %s】:%s' % (city, username ,Content)}}    
        else:
            fromuser = self.leandbs.select_userinfo('key','1','openid')
            dic = {"touser":fromuser,"msgtype":"text","text":{"content":Content}}    
        dics = json.dumps(dic,ensure_ascii=False)
        dics = dics.encode('utf-8')
        url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=%s' % self.get_token()
        result = requests.post(url,data=dics)
        print result.content
        return 'success'

如果不加
dics = dics.encode('utf-8')
这一句转换,则发送中文消息时只能发一个字。超过就会包文本消息为空的错误。




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
发送微信模板消息,需要先在微信公众平台或开放平台申请相关的权限和模板消息ID。然后,可以使用PHP的curl库或者第三方SDK来发送模板消息。 以下是一个使用curl库发送微信模板消息的示例代码: ```php <?php // 模板消息的接口地址 $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN"; // 模板消息的内容,需要根据实际情况替换 $data = array( 'touser' => 'OPENID', 'template_id' => 'TEMPLATE_ID', 'url' => 'http://www.example.com', 'data' => array( 'first' => array('value' => '您好,您有一条新的订单'), 'keyword1' => array('value' => '订单号:123456'), 'keyword2' => array('value' => '商品名称:测试商品'), 'keyword3' => array('value' => '订单金额:100元'), 'remark' => array('value' => '感谢您的支持!'), ), ); // 将数组转换为JSON字符串 $json = json_encode($data); // 使用curl库发送POST请求 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); curl_close($ch); // 输出发送结果 echo $result; ?> ``` 其中,`ACCESS_TOKEN`是调用微信接口所需的access_token,需要先通过接口获取;`OPENID`是接收模板消息的用户的openid;`TEMPLATE_ID`是申请的模板消息ID;`data`是模板消息的内容,需要根据实际情况替换。 注意:在实际使用时,需要根据微信接口的要求进行签名验证等安全处理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值