作者微信 bishe2022

代码功能演示视频在页面下方,请先观看;如需定制开发,联系页面右侧客服
微信模板消息推送

Custom Tab

package com.jeeplus.modules.WeChat.MessageUtils;


import java.util.HashMap;

import java.util.Map;


import org.json.JSONObject;


import com.jeeplus.Exter.utils.HttpClient;


public class WeChat_utils {

public static String we_chat_acctoken() throws Exception {

//获取acctoken

Map<String,String> acctoken_map = new HashMap<String, String>();

acctoken_map.put("grant_type", "client_credential");

//正式appid/secret

acctoken_map.put("appid", "appid");

acctoken_map.put("secret", "secret");

String acctoken_url = "https://api.weixin.qq.com/cgi-bin/token";

String acctoken = HttpClient.doGet(acctoken_url, acctoken_map);

JSONObject acctoken_json = new JSONObject(acctoken);

String access_token =acctoken_json.optString("access_token");

return access_token;

}

}



String access_token = WeChat_utils.we_chat_acctoken();

System.out.println("获取到的access_token:" + access_token);

String message_url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token;

String url = "";

com.alibaba.fastjson.JSONObject json = Create_Json_zs.create_pay_success_Json("openid", url);

String mess = HttpClient.sendHttpPost(message_url, json.toString());



package com.jeeplus.modules.WeChat.MessageUtils;


import java.util.LinkedHashMap;

import java.util.Map;


import org.springframework.stereotype.Controller;


import com.alibaba.fastjson.JSONObject;

@Controller

public class CreateJson  {

  

private static Map<String, Object> map;

 

private static Map<String, Object> data;


/**

* 发送<证书办理>模板消息

* @see 9rYlM4uASPcQji9Xel0CjtjFdDNEXjf6gtJN4DyB4h0(模板ID)

* @param openid

*            接收用户OPENID

* @param url

*            点击模板后跳转地址

* @return JSONObject

*/

@SuppressWarnings("unchecked")

public static JSONObject create_pay_success_Json(String wxopenid, String url) {

// 模板id(正式)

String template_id = "模板id";

// 模板的主题颜色

String topcolor = "#008000";

// 构造json包

map = new LinkedHashMap<String, Object>();

data = new LinkedHashMap<String, Object>();

 

LinkedHashMap<String, String> first = new LinkedHashMap<String, String>();

first.put("value", "您好, ");

first.put("color", "#000000");

 

data.put("first", first);

 

LinkedHashMap<String, String> keyword1 = new LinkedHashMap<String, String>();

keyword1.put("value", "121212");

keyword1.put("color", "#000000");

 

data.put("keyword1", keyword1);

LinkedHashMap<String, String> keyword2 = new LinkedHashMap<String, String>();

keyword2.put("value", "工作日:上午 8:30~ 下午 6:00");//领取时间

 

keyword2.put("color", "#000000");

 

data.put("keyword2", keyword2);

 

LinkedHashMap<String, String> remark = new LinkedHashMap<String, String>();

if(get_way.equals("1")) {

remark.put("value", "请尽快到指定地点领取,感谢您的使用!");

 

remark.put("color", "#000000");

}else if(get_way.equals("2")) {

remark.put("value", "请注意查收,感谢您的使用!");

 

remark.put("color", "#000000");

}

 

data.put("remark", remark);

 

map.put("touser", wxopenid);

 

map.put("template_id", template_id);

 

map.put("url", url);

 

map.put("topcolor", topcolor);

 

map.put("data", data); 

JSONObject json = new JSONObject(map);

System.out.println(json);

//JSONObject jsonObject = JSONObject.fromObject(map);

return json;

}



}


Home