From c927efe5490eb43b75d5f6d65631951e891c3f8e Mon Sep 17 00:00:00 2001
From: 935090232@qq.com <ak473600000>
Date: Thu, 07 Jan 2021 23:42:07 +0800
Subject: [PATCH] 公众号模板消息demo
---
zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/MsgDemo.java | 39 +++++++++++++++++++++++++++++++++++++--
1 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/MsgDemo.java b/zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/MsgDemo.java
index 6a2b858..f0757e4 100644
--- a/zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/MsgDemo.java
+++ b/zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/MsgDemo.java
@@ -1,5 +1,10 @@
package com.matrix.system.wechart.templateMsg;
+import com.alibaba.fastjson.JSONObject;
+import com.matrix.component.tools.HttpClientUtil;
+import com.matrix.core.pojo.AjaxResult;
+import com.matrix.system.shopXcx.api.WeChatGzhApiTools;
+import com.matrix.system.shopXcx.bean.ShopAdvertisType;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
@@ -8,13 +13,43 @@
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+import javax.swing.text.html.HTML;
import java.io.IOException;
-
+@Controller
+@RequestMapping(value = "test")
public class MsgDemo {
+ @Value("${gzh_appid}")
+ String gzhAppId;
- public static void main(String[] args) {
+ @Value("${gzh_secret}")
+ String gzhSecret;
+
+
+ @RequestMapping("/template")
+ @ResponseBody
+ public AjaxResult template() {
+ GzhTemplateMessagePojo messagePojo=new GzhTemplateMessagePojo();
+ messagePojo.setTouser("123");
+ messagePojo.setTemplate_id("543");
+ messagePojo.setUrl("231");
+ messagePojo.setMiniprogram("65475234","/123/234123412");
+ messagePojo.setFirst("1231","#453454");
+ messagePojo.setKeyWord("1231","#453454");
+ System.out.println(JSONObject.toJSON(messagePojo).toString());
+ String ACCESS_TOKEN=WeChatGzhApiTools.getAccessToken(gzhAppId,gzhSecret);
+ String url="https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+ACCESS_TOKEN;
+ JSONObject result= HttpClientUtil.sendPostWithJson(url,JSONObject.toJSON(messagePojo).toString());
+ System.out.println(result.toString());
+ return AjaxResult.buildSuccessInstance("1");
+
+
}
}
--
Gitblit v1.9.1