You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					58 lines
				
				2.7 KiB
			
		
		
			
		
	
	
					58 lines
				
				2.7 KiB
			| 
											3 years ago
										 | package com.ynxbd.wx.wxfactory.message;
 | ||
|  | 
 | ||
|  | import com.ynxbd.common.helper.common.JsonHelper;
 | ||
|  | import com.ynxbd.common.result.JsonResult;
 | ||
|  | import com.ynxbd.wx.wxfactory.utils.WxRequestHelper;
 | ||
|  | 
 | ||
|  | import java.util.HashMap;
 | ||
|  | import java.util.Map;
 | ||
|  | 
 | ||
|  | public class Test {
 | ||
|  |        // https://card.wecity.qq.com/oauth/code?authType=2&isDepart=2&bizType=04107&appid=wx1e30610a28d189a8&cityCode=532900&channel=AAHI73GI-td3vH9gFEQz7c4t&orgChnlCrtfCodg=BqK1kMStlhVDgN2uHf4EsLK%2FF2LjZPYJ81nK2eYQqxtzkyzgPuFW4v%2F09RHEVY9b&orgCodg=H53292700161&orgAppId=1GK9TR5LL0IA76430B0A0000114767F4&redirectUrl=http%3A%2F%2Fwww.wsxrmyy.cn%2Fwx%2Fweb%2Fwx-medical.html%3FcallNo%3Drecipe
 | ||
|  | 
 | ||
|  |     // https://card.wecity.qq.com/openAuth/info?authType=2&isDepart=2&appid=wx1e30610a28d189a8&cityCode=532900&channel=AAHI73GI-td3vH9gFEQz7c4t&bizType=04107&orgCodg=H53292700161&orgAppId=1GKPLMN2N0NCE2470B0A0000D6498453&orgChnlCrtfCodg=BqK1kMStlhVDgN2uHf4EsLK%2FF2LjZPYJ81nK2eYQqxtzkyzgPuFW4v%2F09RHEVY9b&redirectUrl=http://www.wsxrmyy.cn/wx/web/wx-medical.html?callNo=recipe
 | ||
|  | 
 | ||
|  |     /**
 | ||
|  |      * 小程序关联公众号推送
 | ||
|  |      *
 | ||
|  |      * @param accessToken accessToken
 | ||
|  |      * @param appId       appId
 | ||
|  |      */
 | ||
|  |     public static void push(String accessToken, String openid, String appId, String templateId, String url, String miniProgram, String... data) {
 | ||
|  |         if (accessToken == null) {
 | ||
|  |             return;
 | ||
|  |         }
 | ||
|  | 
 | ||
|  |         Map<String, Map<String, Object>> dataMap = new HashMap<>();
 | ||
|  | 
 | ||
|  |         if (data != null && data.length > 0) {
 | ||
|  |             Map<String, Object> itemMap;
 | ||
|  |             for (int i = 0; i < data.length; i++) {
 | ||
|  |                 itemMap = new HashMap<>();
 | ||
|  |                 itemMap.put("value", data[i]);
 | ||
|  |                 dataMap.put(("keyword" + (i + 1)), itemMap);
 | ||
|  |             }
 | ||
|  |         }
 | ||
|  |         System.out.println(JsonHelper.toJsonString(dataMap));
 | ||
|  | 
 | ||
|  |         JsonResult respJson = WxRequestHelper.postBody("https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=" + accessToken, params -> {
 | ||
|  |             params.put("touser", openid); // 公众号的openid
 | ||
|  | 
 | ||
|  |             Map<String, Object> mpTemplateMsg = new HashMap<>();
 | ||
|  |             mpTemplateMsg.put("appid", appId);
 | ||
|  |             mpTemplateMsg.put("template_id", templateId);
 | ||
|  | 
 | ||
|  |             if (url != null && !"".equals(url)) {
 | ||
|  |                 mpTemplateMsg.put("url", "url");
 | ||
|  |             }
 | ||
|  | 
 | ||
|  |             if (miniProgram != null && !"".equals(miniProgram)) {
 | ||
|  |                 mpTemplateMsg.put("miniprogram", miniProgram);
 | ||
|  |             }
 | ||
|  |             mpTemplateMsg.put("data", JsonHelper.toJsonString(dataMap));
 | ||
|  |             params.put("mp_template_msg", mpTemplateMsg);
 | ||
|  |         });
 | ||
|  |         System.out.println(respJson);
 | ||
|  |     }
 | ||
|  | }
 |