public static void sendRegisterMessage(String toWho, String title, String description, String campaignId) { Http h = new Http(); HttpRequest req = new HttpRequest(); req.setMethod('POST'); req.setHeader('Accept-Encoding', 'gzip,deflate'); req.setHeader('Content-Type', 'text/xml;charset=UTF-8'); req.setHeader('User-Agent', 'Jakarta Commons-HttpClient/3.1'); String access_token = getToken(); String sendMsg = '{"touser":' + '"' + toWho + '","msgtype":"news","news":{"articles":[{"title":"' + title + '","description":"' + description + '","url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa16c53b4e1de217b&redirect_uri=https://richs-wechat-developer-edition.ap16.force.com/WechatRegister?strId=' + campaignId + '&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect","picurl":"http://img2.imgtn.bdimg.com/it/u=3585298255,2069611043&fm=26&gp=0.jpg"}]}}'; req.setBody(sendMsg); req.setEndpoint('https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' + access_token); String bodyRes = ''; HttpResponse res = new HttpResponse() ; try { res = h.send(req); bodyRes = res.getBody(); } catch (System.CalloutException e) { System.debug('Callout error: ' + e); ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL, e.getMessage())); } }
Wechat 发送回复消息
最新推荐文章于 2023-12-10 14:33:26 发布