|
@@ -8,38 +8,44 @@ import java.util.Map;
|
|
|
|
|
|
public class PushWxMessage {
|
|
|
|
|
|
- public static String sendMessage(AppEntry appinfo,TemplateEntry template){
|
|
|
- try {
|
|
|
- Map params = new HashMap();
|
|
|
- params.put("secret", appinfo.getSecret());
|
|
|
- params.put("appid", appinfo.getAppId());
|
|
|
- params.put("grant_type", "client_credential");
|
|
|
- String result = HttpCilentUntil.httpGetToString(
|
|
|
- "https://api.weixin.qq.com/cgi-bin/token", params);
|
|
|
- JSONObject jsonObject = JSON.parseObject(result);
|
|
|
- String access_token = jsonObject.get("access_token").toString();
|
|
|
- String pushUrl = new StringBuffer("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=").append(access_token).toString();
|
|
|
- result = HttpCilentUntil.httpJsonToString(pushUrl, JSON.toJSONString(template));
|
|
|
- jsonObject = JSON.parseObject(result);
|
|
|
- String errCode = jsonObject.get("errcode").toString();
|
|
|
- String errMsg = jsonObject.get("errmsg").toString();
|
|
|
- System.out.println(errCode);
|
|
|
- return errCode;
|
|
|
- }catch (Throwable e){
|
|
|
- e.printStackTrace();
|
|
|
- return "-1";
|
|
|
- }
|
|
|
- }
|
|
|
+ public static String sendMessage(AppEntry appinfo, TemplateEntry template) {
|
|
|
+ try {
|
|
|
+ Map params = new HashMap();
|
|
|
+ params.put("secret", appinfo.getSecret());
|
|
|
+ params.put("appid", appinfo.getAppId());
|
|
|
+ params.put("grant_type", "client_credential");
|
|
|
+ String result = HttpCilentUntil.httpGetToString(
|
|
|
+ "https://api.weixin.qq.com/cgi-bin/token", params);
|
|
|
+ JSONObject jsonObject = JSON.parseObject(result);
|
|
|
+ String access_token = jsonObject.get("access_token").toString();
|
|
|
+ String pushUrl = new StringBuffer("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=").append(access_token).toString();
|
|
|
+ result = HttpCilentUntil.httpJsonToString(pushUrl, JSON.toJSONString(template));
|
|
|
+ jsonObject = JSON.parseObject(result);
|
|
|
+ String errCode = jsonObject.get("errcode").toString();
|
|
|
+ String errMsg = jsonObject.get("errmsg").toString();
|
|
|
+ System.out.println(errCode);
|
|
|
+ return errCode;
|
|
|
+ } catch (Throwable e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return "-1";
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
- AppEntry app=AppEntry.builder().appId("wxfd6e42e05b91163c").secret("7c4e39a33bf8b66beb919b9ad0a15832").build();
|
|
|
- HashMap<String,ValEntry> dataMap=new HashMap();
|
|
|
- dataMap.put("thing1",ValEntry.builder().value("this is one").build());
|
|
|
- dataMap.put("thing2",ValEntry.builder().value("this is two").build());
|
|
|
- dataMap.put("time3",ValEntry.builder().value("2021-07-23 20:00").build());
|
|
|
- dataMap.put("thing4",ValEntry.builder().value("Bella").build());
|
|
|
- TemplateEntry tpl=TemplateEntry.builder().template_id("3RatcsOA-T0Dsgevr-1UGvYzZvhS0UY9A86fnTFax50").touser("oc6xx5Z4DGNuRYKp7EHANCkq5mII").page("pages/login/index").data(dataMap).build();
|
|
|
- PushWxMessage.sendMessage(app,tpl);
|
|
|
+ AppEntry app = AppEntry.builder().appId("wxfd6e42e05b91163c").secret("7c4e39a33bf8b66beb919b9ad0a15832").build();
|
|
|
+ HashMap<String, ValEntry> dataMap = new HashMap();
|
|
|
+ dataMap.put("thing1", ValEntry.builder().value("this is one").build());
|
|
|
+ dataMap.put("thing2", ValEntry.builder().value("this is two").build());
|
|
|
+ dataMap.put("time3", ValEntry.builder().value("2021-07-23 20:00").build());
|
|
|
+ dataMap.put("thing4", ValEntry.builder().value("Bella").build());
|
|
|
+ TemplateEntry tpl = TemplateEntry.builder()
|
|
|
+ .template_id("3RatcsOA-T0Dsgevr-1UGvYzZvhS0UY9A86fnTFax50")
|
|
|
+ .touser("oc6xx5Z4DGNuRYKp7EHANCkq5mII")
|
|
|
+ .page("pages/login/index")
|
|
|
+// .miniprogram_state("trial")
|
|
|
+ .data(dataMap)
|
|
|
+ .build();
|
|
|
+ PushWxMessage.sendMessage(app, tpl);
|
|
|
}
|
|
|
|
|
|
}
|