123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 |
- package com.caimei.modules.order.service;
- import com.alibaba.fastjson.JSONObject;
- import com.caimei.modules.utils.RequestUtil;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.util.Map;
- /**
- * Description
- *
- * @author : Charles
- * @date : 2022/4/12
- */
- @Service
- public class WeChatService {
- @Value("${wx.crm-app-id}")
- private String crmAppId;
- @Value("${wx.crm-app-secret}")
- private String crmAppSecret;
- protected Logger logger = LoggerFactory.getLogger(getClass());
- /**
- * 微信公众号获取access_token
- *
- * @return access_token
- */
- public String getAccessToken() throws Exception {
- String link = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET";
- link = link.replace("APPID", "wx91c4152b60ca91a3");
- link = link.replace("APPSECRET", "a563dd2c07c9c815a4e697c8b6cb73dc");
- String result = RequestUtil.sendGet(link);
- logger.info("微信公众号获取access_token>>>" + result);
- Map<String, Object> map = JSONObject.parseObject(result, Map.class);
- String access_token = (String) map.get("access_token");
- return access_token;
- }
- /**
- * 发货消息推送
- * @param accessToken
- * @param openid
- * @param shopOrderNo 子订单编号
- * @param time 发货时间
- * @param company 快递名称
- * @param companyno 快递编号
- * @param pagePath 跳转链接
- */
- public void sendTemplateMsgy(String accessToken, String openid, String shopOrderNo,String time, String company, String companyno, String pagePath) {
- JSONObject first = new JSONObject();
- first.put("value", "尊敬的采美客户,您购买的订单已经发货啦~");
- JSONObject keyword1 = new JSONObject();
- keyword1.put("value", shopOrderNo);
- JSONObject keyword2 = new JSONObject();
- keyword2.put("value", time);
- JSONObject keyword3 = new JSONObject();
- keyword3.put("value", company);
- JSONObject keyword4 = new JSONObject();
- keyword4.put("value", companyno);
- JSONObject remark = new JSONObject();
- remark.put("value", "收到货后请记得确认收货哟~");
- JSONObject data = new JSONObject();
- data.put("first", first);
- data.put("keyword1", keyword1);
- data.put("keyword2", keyword2);
- data.put("keyword3", keyword3);
- data.put("keyword4", keyword4);
- data.put("remark", remark);
- JSONObject miniProgram = new JSONObject();
- miniProgram.put("appid", "wxf3cd4ae0cdd11c36");
- miniProgram.put("pagepath", pagePath);
- JSONObject json = new JSONObject();
- json.put("touser", openid);
- json.put("template_id", "_Zc6WiUp3hM4yBgT30HkTyA-SmcCN-sjnGpIa6n3rKI");
- json.put("url", "https://www.caimei365.com/");
- json.put("miniprogram", miniProgram);
- json.put("data", data);
- // json 字符串
- String jsonString = json.toJSONString();
- logger.info(">>>>>>>>推送微信模板消息:" + jsonString);
- try {
- String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+accessToken;
- // 发送请求
- String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
- logger.info(">>>>>>>>推送结果:" + result);
- } catch (Exception e) {
- logger.info(">>>>>>>>>推送微信模板消息失败:",e);
- }
- }
- /**
- * 资质机构认证成功消息推送
- * @param accessToken
- * @param openid
- * @param pagePath 跳转链接
- */
- public void sendTemplateMsg(String accessToken, String openid ,String auditTime, String pagePath) {
- JSONObject first = new JSONObject();
- first.put("value", "认证成功通知");
- JSONObject keyword1 = new JSONObject();
- keyword1.put("value", "恭喜您成功成为采美资质机构");
- JSONObject keyword2 = new JSONObject();
- keyword2.put("value", "资质机构");
- JSONObject keyword3 = new JSONObject();
- keyword3.put("value", "审核通过");
- JSONObject keyword4 = new JSONObject();
- keyword4.put("value", auditTime);
- JSONObject remark = new JSONObject();
- remark.put("value", "认证成功后,您将享受到更多的优惠机会。");
- JSONObject data = new JSONObject();
- data.put("first", first);
- data.put("keyword1", keyword1);
- data.put("keyword2", keyword2);
- data.put("keyword3", keyword3);
- data.put("keyword4", keyword4);
- data.put("remark", remark);
- JSONObject miniProgram = new JSONObject();
- miniProgram.put("appid", "wxf3cd4ae0cdd11c36");
- miniProgram.put("pagepath", pagePath);
- JSONObject json = new JSONObject();
- json.put("touser", openid);
- json.put("template_id", "kfzhVTJ6sNOJSgwk8x7Z9_m8S2LRzDfAGtiUgGyO8Zk");
- json.put("url", "https://www.caimei365.com/");
- json.put("miniprogram", miniProgram);
- json.put("data", data);
- // json 字符串
- String jsonString = json.toJSONString();
- logger.info(">>>>>>>>推送微信模板消息:" + jsonString);
- try {
- String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+accessToken;
- // 发送请求
- String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
- logger.info(">>>>>>>>推送结果:" + result);
- } catch (Exception e) {
- logger.info(">>>>>>>>>推送微信模板消息失败:",e);
- }
- }
- /**
- * 资质机构认证失败消息推送
- * @param accessToken
- * @param openid
- * @param pagePath 跳转链接
- */
- public void sendTemplateMessg(String accessToken, String openid, String auditResult,String auditTime, String pagePath) {
- JSONObject first = new JSONObject();
- first.put("value", "认证失败通知");
- JSONObject keyword1 = new JSONObject();
- keyword1.put("value", "您升级采美资质机构认证失败");
- JSONObject keyword2 = new JSONObject();
- keyword2.put("value", "资质机构");
- JSONObject keyword3 = new JSONObject();
- keyword3.put("value", "审核未通过");
- JSONObject keyword4 = new JSONObject();
- keyword4.put("value", auditTime);
- JSONObject keyword5 = new JSONObject();
- keyword5.put("value", auditResult);
- JSONObject remark = new JSONObject();
- remark.put("value", " ");
- JSONObject data = new JSONObject();
- data.put("first", first);
- data.put("keyword1", keyword1);
- data.put("keyword2", keyword2);
- data.put("keyword3", keyword3);
- data.put("keyword4", keyword4);
- data.put("keyword5", keyword5);
- data.put("remark", remark);
- JSONObject miniProgram = new JSONObject();
- miniProgram.put("appid", "wxf3cd4ae0cdd11c36");
- miniProgram.put("pagepath", pagePath);
- JSONObject json = new JSONObject();
- json.put("touser", openid);
- json.put("template_id", "btBvh1LIzTPMIpZNPNIupQnMcMw8_ziyQ6CGV68eN7s");
- json.put("url", "https://www.caimei365.com/");
- json.put("miniprogram", miniProgram);
- json.put("data", data);
- // json 字符串
- String jsonString = json.toJSONString();
- logger.info(">>>>>>>>推送微信模板消息:" + jsonString);
- try {
- String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+accessToken;
- // 发送请求
- String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
- logger.info(">>>>>>>>推送结果:" + result);
- } catch (Exception e) {
- logger.info(">>>>>>>>>推送微信模板消息失败:",e);
- }
- }
- /**
- * 供应商审核失败消息推送
- * @param accessToken
- * @param openid
- * @param pagePath 跳转链接
- */
- public void sendTemplate(String accessToken, String openid,String shopName,String auditNote,String auditTime, String pagePath) {
- JSONObject first = new JSONObject();
- first.put("value", "您提交的供应商账号注册申请审核失败。");
- JSONObject keyword1 = new JSONObject();
- keyword1.put("value", shopName);
- JSONObject keyword2 = new JSONObject();
- keyword2.put("value", "账号注册");
- JSONObject keyword3 = new JSONObject();
- keyword3.put("value", auditNote);
- JSONObject keyword4 = new JSONObject();
- keyword4.put("value", auditTime);
- JSONObject remark = new JSONObject();
- remark.put("value", "请修改重新提交审核。");
- JSONObject data = new JSONObject();
- data.put("first", first);
- data.put("keyword1", keyword1);
- data.put("keyword2", keyword2);
- data.put("keyword3", keyword3);
- data.put("keyword4", keyword4);
- data.put("remark", remark);
- JSONObject miniProgram = new JSONObject();
- miniProgram.put("appid", "wxf3cd4ae0cdd11c36");
- miniProgram.put("pagepath", pagePath);
- JSONObject json = new JSONObject();
- json.put("touser", openid);
- json.put("template_id", "QogD0Mu5zvNo51hqJXXNYiVByuDmYLxg2kxHUMqlyCI");
- json.put("url", "https://www.caimei365.com/");
- json.put("miniprogram", miniProgram);
- json.put("data", data);
- // json 字符串
- String jsonString = json.toJSONString();
- logger.info(">>>>>>>>推送微信模板消息:" + jsonString);
- try {
- String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+accessToken;
- // 发送请求
- String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
- logger.info(">>>>>>>>推送结果:" + result);
- } catch (Exception e) {
- logger.info(">>>>>>>>>推送微信模板消息失败:",e);
- }
- }
- /**
- * 商品审核未通过消息推送
- * @param accessToken
- * @param openid
- * @param pagePath 跳转链接
- */
- public void sendTemp(String accessToken, String openid,String name,String auditTime, String pagePath) {
- JSONObject first = new JSONObject();
- first.put("value", "商品审核未通过通知");
- JSONObject keyword1 = new JSONObject();
- keyword1.put("value", "抱歉,您发布的商品未通过审核");
- JSONObject keyword2 = new JSONObject();
- keyword2.put("value", "审核未通过");
- JSONObject keyword3 = new JSONObject();
- keyword3.put("value", auditTime);
- JSONObject keyword4 = new JSONObject();
- keyword4.put("value", name);
- JSONObject remark = new JSONObject();
- remark.put("value", "请前往采美网站修改商品信息重新发布");
- JSONObject data = new JSONObject();
- data.put("first", first);
- data.put("keyword1", keyword1);
- data.put("keyword2", keyword2);
- data.put("keyword3", keyword3);
- data.put("keyword4", keyword4);
- data.put("remark", remark);
- JSONObject miniProgram = new JSONObject();
- miniProgram.put("appid", "wxf3cd4ae0cdd11c36");
- miniProgram.put("pagepath", pagePath);
- JSONObject json = new JSONObject();
- json.put("touser", openid);
- json.put("template_id", "oGiOHlJgx0L8rWmq6wqXHUIZjIzuPkiRu2xbqTE26Tg");
- json.put("url", "https://www.caimei365.com/");
- json.put("miniprogram", miniProgram);
- json.put("data", data);
- // json 字符串
- String jsonString = json.toJSONString();
- logger.info(">>>>>>>>推送微信模板消息:" + jsonString);
- try {
- String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+accessToken;
- // 发送请求
- String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
- logger.info(">>>>>>>>推送结果:" + result);
- } catch (Exception e) {
- logger.info(">>>>>>>>>推送微信模板消息失败:",e);
- }
- }
- /**
- * 商品审核未通过消息推送
- * @param accessToken
- * @param openid
- * @param pagePath 跳转链接
- */
- public void messteme(String accessToken, String openid,String name,String qualificationNo,String auditTime,String proName, String pagePath) {
- JSONObject first = new JSONObject();
- first.put("value", "您好,您有商品资质证书即将到期。");
- JSONObject keyword1 = new JSONObject();
- keyword1.put("value", name);
- JSONObject keyword2 = new JSONObject();
- keyword2.put("value", "医疗器械注册证");
- JSONObject keyword3 = new JSONObject();
- keyword3.put("value", qualificationNo);
- JSONObject keyword4 = new JSONObject();
- keyword4.put("value", auditTime);
- JSONObject remark = new JSONObject();
- remark.put("value", proName);
- JSONObject data = new JSONObject();
- data.put("first", first);
- data.put("keyword1", keyword1);
- data.put("keyword2", keyword2);
- data.put("keyword3", keyword3);
- data.put("keyword4", keyword4);
- data.put("remark", remark);
- JSONObject miniProgram = new JSONObject();
- miniProgram.put("appid", "wxf3cd4ae0cdd11c36");
- miniProgram.put("pagepath", pagePath);
- JSONObject json = new JSONObject();
- json.put("touser", openid);
- json.put("template_id", "gpD9TqBpkgaw3YSM_JPk4WSTwKZY0hxrBCH0SjzNKY4");
- json.put("url", "https://www.caimei365.com/");
- json.put("miniprogram", miniProgram);
- json.put("data", data);
- // json 字符串
- String jsonString = json.toJSONString();
- logger.info(">>>>>>>>推送微信模板消息:" + jsonString);
- try {
- String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+accessToken;
- // 发送请求
- String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
- logger.info(">>>>>>>>推送结果:" + result);
- } catch (Exception e) {
- logger.info(">>>>>>>>>推送微信模板消息失败:",e);
- }
- }
- }
|