|
|
@@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.http.HttpEntity;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.MediaType;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
@@ -22,13 +23,13 @@ import java.util.Map;
|
|
|
@Component
|
|
|
public class WechatApi {
|
|
|
|
|
|
-// @Value("${wechat.appid}")
|
|
|
-// private String appId;
|
|
|
-//
|
|
|
-// @Value("${wechat.secret}")
|
|
|
-// private String secret;
|
|
|
- private String appId = "wx7670b3b1b1cfcd47";
|
|
|
- private String secret = "c6e5726c7039092a907c3242c8d3e406";
|
|
|
+ @Value("${wx.mp.configs[0].appId}")
|
|
|
+ private String appId;
|
|
|
+
|
|
|
+ @Value("${wx.mp.configs[0].secret}")
|
|
|
+ private String secret;
|
|
|
+// private String appId = "wx7670b3b1b1cfcd47";
|
|
|
+// private String secret = "c6e5726c7039092a907c3242c8d3e406";
|
|
|
|
|
|
private String accessToken;
|
|
|
private long tokenExpireTime;
|
|
|
@@ -64,6 +65,7 @@ public class WechatApi {
|
|
|
return "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + URLEncoder.encode(ticket, "UTF-8");
|
|
|
}
|
|
|
|
|
|
+ //发送长期订阅消息
|
|
|
public static void sendSubscribeMessage(String accessToken, String openId) {
|
|
|
//accessToken = "97_AWdZem-aCEBY8bt8vlQV0Hz1OmJnXGCRwWZiiUAuVxZmwYtIJbxP13ADoqZ5p8cFBef2JrF8lo3wMUjvGCUTsXuhA0hrlG-RYhPzuoRFHh8o4Iwxj0Ai4TDWvGcWEQhAFAEMY";
|
|
|
String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/bizsend?access_token=" + accessToken;
|
|
|
@@ -90,6 +92,8 @@ public class WechatApi {
|
|
|
System.out.println("微信返回结果:" + result);
|
|
|
}
|
|
|
|
|
|
+ //发送模板消息
|
|
|
+ @Async
|
|
|
public void sendTemplateMessage(String accessToken, String openId, Date payTime, String userName, BigDecimal payPrice,String orderCode) {
|
|
|
//accessToken = "97_AWdZem-aCEBY8bt8vlQV0Hz1OmJnXGCRwWZiiUAuVxZmwYtIJbxP13ADoqZ5p8cFBef2JrF8lo3wMUjvGCUTsXuhA0hrlG-RYhPzuoRFHh8o4Iwxj0Ai4TDWvGcWEQhAFAEMY";
|
|
|
String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
|