使用postman测试正常,使用代码测试的时候报获取不到openid,或openid为空,使用自己的client获取传过来的参数是正常的,
errcode:40003 errmsg:invalid openid rid: 60754300-6c199ef6-616a2735
client发起请求
thing31.Value = "力顶天地"
thing3.Value = "回复消息"
time4.Value = "2020-01-01 12:20"
data1.Thing2 = thing31
data1.Time4 = time4
data1.Thing3 = thing3
message.Data = data1
message.Template_id = "QMd_2_UXn0mYnB5hHWTGVXgqE1BMeXPv08FO3YFHiOo"
message.ToUser = "ocI0k0UScnY4vqLnLTwUwzOWejzY"
message.Page = "/pages/product_info/product_info?id=027820373b8f88b9ffd31517ed65d1a8"
message.Miniprogram_state = "developer"
wxMessage, err = json.Marshal(message)
if err != nil {
e.Error(http.StatusServiceUnavailable, "json转化错误", *c)
return
}
str, err = WxToken()
client := http.Client{}
resp, err = client.Post(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=%s", str), "application/json", bytes.NewBuffer(wxMessage))
上面的请求地址已更换成自己的
server端接收参数
router := gin.Default()
router.POST("/test", func(c *gin.Context) {
var message Message
err := c.Bind(&message)
if err != nil {
fmt.Println(err)
}
me,_ := json.Marshal(message)
fmt.Println(string(me))
c.JSON(http.StatusOK,me)
})
router.Run(":8888")
获取的参数
{"touser":"ocI0k0UScnY4vqLnLTwUwzOWejzY","template_id":"QMd_2_UXn0mYnB5hHWTGVXgqE1BMeXPv08FO3YFHiOo","data":{"thing2":{"value":"力顶天地"},"thing3":{"value":"回复消息"},"time4":{"value":"2020-01-01 12:20"}},"page":"/pages/product_info/product_info?id=027820373b8f88b9ffd31517ed65d1a8","miniprogram_state":"developer"}
你好,先自查是不是用的小程序帐号请求了公众号接口。