|
@@ -0,0 +1,100 @@
|
|
|
+package com.miaxis.test;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.miaxis.ZzjsApplication;
|
|
|
+import com.miaxis.feign.dto.AddTemplate;
|
|
|
+import com.miaxis.feign.dto.WxSend;
|
|
|
+import com.miaxis.feign.service.IWxAddTemplate;
|
|
|
+import com.miaxis.feign.service.IWxSendService;
|
|
|
+import com.miaxis.feign.service.IWxTemplateList;
|
|
|
+import com.miaxis.feign.service.IWxgetTokenService;
|
|
|
+import org.junit.Test;
|
|
|
+import org.junit.runner.RunWith;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+import org.springframework.test.context.junit4.SpringRunner;
|
|
|
+
|
|
|
+@SpringBootTest(classes = ZzjsApplication.class)
|
|
|
+@RunWith(SpringRunner.class)
|
|
|
+public class WxTest {
|
|
|
+
|
|
|
+ private String token ="45_NDxpMTA7H4BUlbToZa9IHTCe4zyctpzyt_RNoaIOAGxTAtT_OQ3fZ2iTuSyXjILqC21eG8Pcyi6756FCSR0YWDbXyMoyL3GdJ9JHNm-qhZQZfEIwLe12TC2_b7f3Zmkj684Ph7xfu6bmNB8TSRJcAEAYXP";
|
|
|
+ @Autowired
|
|
|
+ private IWxgetTokenService wxgetTokenService;
|
|
|
+ @Autowired
|
|
|
+ private IWxSendService wxSendService;
|
|
|
+ @Autowired
|
|
|
+ private IWxAddTemplate wxAddTemplate;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IWxTemplateList wxTemplateList;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Value("${app.appid}")
|
|
|
+ private String appid;
|
|
|
+
|
|
|
+ @Value("${app.secret}")
|
|
|
+ private String secret;
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void getWxgetTokenService(){
|
|
|
+ String result = wxgetTokenService.getAccessToken("client_credential",appid,secret);
|
|
|
+
|
|
|
+ JSONObject json = JSONObject.parseObject(result);
|
|
|
+ String accessToken = json.get("access_token").toString();
|
|
|
+ String expiresIn = json.get("expires_in").toString();
|
|
|
+
|
|
|
+ System.out.println(accessToken);
|
|
|
+ System.out.println(expiresIn);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void getWxSendService(){
|
|
|
+ WxSend wxSend = new WxSend();
|
|
|
+ wxSend.setAccess_token(token);
|
|
|
+ wxSend.setTouser("oO7PJ5JxqYj0kVYLb1e3FG55mD8E");
|
|
|
+ wxSend.setTemplate_id("NlZAFJj1p5aHFOg6BBesP7xFAJh5kIZ0kp_YwtJje0g");
|
|
|
+ wxSend.setPage("/pages/index/index?active=user");
|
|
|
+
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ JSONObject jsonObject1 = new JSONObject();
|
|
|
+ JSONObject jsonObject2 = new JSONObject();
|
|
|
+ JSONObject jsonObject3 = new JSONObject();
|
|
|
+ jsonObject1.put("value","2019年10月1日");
|
|
|
+ jsonObject2.put("value","林霖强");
|
|
|
+ jsonObject3.put("value","3");
|
|
|
+ jsonObject.put("time3",jsonObject1);
|
|
|
+ jsonObject.put("name1",jsonObject2);
|
|
|
+ jsonObject.put("thing2",jsonObject3);
|
|
|
+
|
|
|
+ wxSend.setData(jsonObject);
|
|
|
+ wxSend.setMiniprogram_state("developer");
|
|
|
+ wxSend.setLang("zh_CN");
|
|
|
+
|
|
|
+ String result = wxSendService.sendMessage(token,wxSend);
|
|
|
+ System.out.println(result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void addWxTemplate(){
|
|
|
+ AddTemplate addTemplate = new AddTemplate();
|
|
|
+ addTemplate.setAccess_token(token);
|
|
|
+ addTemplate.setTid("gAayj95qwP5C59NApKj9VCis3zpnfg5G3TqJIOx-CGc");
|
|
|
+ Integer[] intList = {1,2,3};
|
|
|
+ addTemplate.setKidList(intList);
|
|
|
+ addTemplate.setSceneDesc("测试模板");
|
|
|
+ String result = wxAddTemplate.addTemplate(token,addTemplate);
|
|
|
+ System.out.println(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void getWxTemplate(){
|
|
|
+ String result = wxTemplateList.getAccessToken(token);;
|
|
|
+ System.out.println(result);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|