E企盈营销工具技术服务商 热线:4006-838-530

微信推送,微信小程序 之推送功能

E企盈直播平台营销卖货系统

添加依赖!–微信小程序模版推送–dependencygroupIdcom.github.binarywang/groupIdartifactIdweixin-java-miniapp/artifactIdversion3.4.0/version/dependencyimportcn.binarywang.wx.miniapp.api.WxMaService;importcn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;importcn.binarywang.wx.miniapp.bean.WxMaTemplateData;importcn.binarywang.wx.miniapp.bean.WxMaTemplateMessage;importcn.binarywang.wx.miniapp.config.WxMaInMemoryConfig;importcom.alibaba.fastjson.JSONObject;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.http.ResponseEntity;importorg.springframework.stereotype.Controller;importorg.springframework.web.bind.annotation.CrossOrigin;importorg.springframework.web.bind.annotation.RequestMapping;importorg.springframework.web.bind.annotation.ResponseBody;importorg.springframework.web.client.RestTemplate;importjava.util.ArrayList;importjava.util.HashMap;importjava.util.List;importjava.util.Map;/小程序推送到货消息给指定用户/@CrossOrigin(origins=””,maxAge=3600)@RequestMapping(“/pushMsgApi”)@ControllerpublicclassApiPushMsgController{//这是用来请求微信的get和post@AutowiredprivateRestTemplaterestTemplate;/useCode1为推送商品给用户的模板///发送推送消息给用户@RequestMapping(“/push”)@ResponseBodypublicStringpush(intuseCode,MapString,Stringmap){//1,配置小程序信息WxMaInMemoryConfigwxConfig=newWxMaInMemoryConfig();wxConfig.setAppid(“wx…….”);//小程序appidwxConfig.setSecret(“3e…………..e3e9”);//小程序AppSecretWxMaServicewxMaService=newWxMaServiceImpl();wxMaService.setWxMaConfig(wxConfig);//2,设置装模版信息的List(keyword1:类型,keyword2:内容)ListWxMaTemplateDatatemplateDataList=newArrayList();//3,设置单一用户推送消息WxMaTemplateMessagetemplateMessage=null;/useCode1为推送商品给用户的模板,(useCode自定义的)/if(useCode==1){//商品名WxMaTemplateDatadata1=newWxMaTemplateData(“keyword1”,map.get(“goodsName”));//订单号WxMaTemplateDatadata2=newWxMaTemplateData(“keyword2”,map.get(“orderNum”));//联系电话WxMaTemplateDatadata3=newWxMaTemplateData(“keyword3”,map.get(“agencyTel”));//取货地点WxMaTemplateDatadata4=newWxMaTemplateData(“keyword4”,map.get(“agencyAddress”));//温馨提示WxMaTemplateDatadata5=newWxMaTemplateData(“keyword5″,”请您尽快到代理点取货”);templateDataList.add(data1);templateDataList.add(data2);templateDataList.add(data3);templateDataList.add(data4);templateDataList.add(data5);//(formId必须与openId一一对应,此处的formId为微信的预支付id–prepayId)templateMessage=WxMaTemplateMessage.builder().toUser(map.get(“openId”))//要推送的用户openid.formId(map.get(“prepayId”))//收集到的formid/prepayId.templateId(“Zv……………………………………………….Ae7Y”)//推送的模版id(在小程序后台设置).data(templateDataList)//模版信息.page(“pages/Authorization/Authorization”)//要跳转到小程序那个页面.build();}//统一推送/WxMaUniformMessagewxMaUniformMessage=WxMaUniformMessage.builder()//.toUser(“ovSIR5UO9_mbCHCoXotkVAOGcWj0”).toUser(openId).formId(formId).templateId(“ZvUjtcBXyQrB3dsfZtq3oOEp4YCSsqOg46qyNJHAe7Y”).data(templateDataList).build();///4,发起推送try{//wxMaService.getMsgService().sendKefuMsg(templateMessage);wxMaService.getMsgService().sendTemplateMsg(templateMessage);//wxMaService.getMsgService().sendUniformMsg(wxMaUniformMessage);}catch(Exceptione){System.out.println(“推送失败:”+e.getMessage());returne.getMessage();}return”推送成功”;}}

赞(0) 打赏
未经允许不得转载:E企盈小程序开发-热线:4006-838-530 » 微信推送,微信小程序 之推送功能
分享到: 更多 (0)
E企盈小程序直播营销卖货系统
E企盈直播平台营销卖货系统

评论 抢沙发

E企盈小程序开发

联系我们联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏