调用微信的群发消息的时候一直遇到一个问题,如下
{ "errcode"=>40130, "errmsg"=>"invalid openid list size, at least two openid hint: [i..dUA0888ge10]" }
问题详情
一开始测试的参数形式是:
{ touser: ['openid_1', 'openid_2', 'openid_3'], msgtype: 'text', text: { content: '测试'}}
然后调用方法如下:
# 发送文本消息 def self.send_bai_e_ke_cheng(_open_ids) access_token = get_access_token //这个get_access_token要自己写,是获取access_token的方法。 uri = "https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token=#{access_token}" json_params = { touser: ['openid_1', 'openid_2', 'openid_3'], msgtype: 'text', text: { content: '测试'}} result = JSON.parse(RestClient.post(uri, json_params)) return result end
接下来在console里边调用的时候,一直报
{"errcode"=>40130, "errmsg"=>"invalid openid list size, at least two openid hint: [IsGYja0367age1]"}
之后通过在线接口的测试和对参数的转换,发现只要把参数转成json就行了:
{"errcode"=>40130, "errmsg"=>"invalid openid list size, at least two openid hint: [IsGYja0367age1]"}.to_json
console退出,然后再尝试调用,成功,返回信息如下:
{"errcode"=>0, "errmsg"=>"send job submission success", "msg_id"=>2568957780}
作者:村南一枝花
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。