微信小程序-发送消息通知

1.get access token

1
2
3
res = RestClient.get 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='+app_id + '&secret=' + app_secret
json = JSON.parse res.body
access_token = json['access_token']
>

2.template

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
"touser": "OPENID",
"template_id": "TEMPLATE_ID",
"page": "index",
"form_id": "FORMID",
"data": {
"keyword1": {
"value": "339208499"
},
"keyword2": {
"value": "2015年01月05日 12:30"
},
"keyword3": {
"value": "粤海喜来登酒店"
} ,
"keyword4": {
"value": "广州市天河区天河路208号"
}
},
"emphasis_keyword": "keyword1.DATA"
}

3.send

1
res= RestClient.post 'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=' + access_token, temp.to_json, {content_type: :json, accept: :json}