3 changed files with 118 additions and 2 deletions
@ -0,0 +1,56 @@ |
|||
package com.research.web.controller.client; |
|||
|
|||
import cn.hutool.http.HttpRequest; |
|||
import com.alibaba.fastjson2.JSON; |
|||
import com.alibaba.fastjson2.JSONObject; |
|||
import com.research.common.annotation.Anonymous; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.scheduling.annotation.Async; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @Author zzc |
|||
* @Package com.research.web.controller.client |
|||
* @Date 2026/5/14 11:28 |
|||
* @description: |
|||
*/ |
|||
@Slf4j |
|||
@Api(tags = "任务相关") |
|||
@RestController |
|||
@RequestMapping("/test") |
|||
public class SendMessage { |
|||
|
|||
@Anonymous |
|||
@ApiOperation(value = "通知测试") |
|||
@GetMapping("/sendWxMessage") |
|||
public String sendWxMessage() { |
|||
String gzhUrl = String.format("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=%1$s", getAccessToken()); |
|||
// HttpRequest.post(wxMessageUrl).body(JSON.toJSONString(sendMiniMessage)).execute().body();
|
|||
return HttpRequest.post(gzhUrl).body("{\"data\":{\"amount6\":{\"value\":\"400.00\"},\"character_string1\":{\"value\":\"2054046697255997440\"},\"thing3\":{\"value\":\"孙健\"},\"thing5\":{\"value\":\"小动物X光机\"},\"time2\":{\"value\":\"2026-05-12 11:51:09\"}},\"miniprogram\":{\"appid\":\"wx243c7267534c1f24\",\"pagepath\":\"/pages/gly/comList/detail?orderSn=2054046697255997440\"},\"page\":\"/pages/gly/comList/detail?orderSn=2054046697255997440\",\"template_id\":\"f2Iqy0Zf4JbbMtqjS2-AJ8hkir6zgyFIB0RTCUmCizo\",\"touser\":\"oQQ5_2CkWVyR9x_44IM3dqnjxEr8\",\"url\":\"/pages/gly/comList/detail?orderSn=2054046697255997440\"}") |
|||
.timeout(5000).execute().body(); |
|||
} |
|||
|
|||
public static String getAccessToken() { |
|||
JSONObject jsonObject = new JSONObject(); |
|||
jsonObject.put("appid", "wxd3376bd21c4d12cb"); |
|||
jsonObject.put("secret", "f7b2bf60a9da8691bc148d70ad4ebdb4"); |
|||
jsonObject.put("grant_type", "client_credential"); |
|||
|
|||
|
|||
String body = HttpRequest.post("https://api.weixin.qq.com/cgi-bin/stable_token") |
|||
.body(jsonObject.toJSONString()) |
|||
// .form("grant_type", "client_credential")
|
|||
// .form("appid", GZH_APPID)
|
|||
// .form("secret", GZH_SECRET)
|
|||
.execute().body(); |
|||
log.info("getAccessToken: {}", body); |
|||
return JSONObject.parseObject(body).getString("access_token"); |
|||
} |
|||
} |
|||
@ -0,0 +1,60 @@ |
|||
package com.research.common.utils; |
|||
|
|||
import cn.hutool.http.HttpRequest; |
|||
import com.alibaba.fastjson2.JSON; |
|||
import com.alibaba.fastjson2.JSONObject; |
|||
import com.research.common.wechat.WxConstant; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.scheduling.annotation.Async; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @Author zzc |
|||
* @Package com.research.common.utils |
|||
* @Date 2026/5/14 13:58 |
|||
* @description: |
|||
*/ |
|||
@Slf4j |
|||
public class SendMessageUtil { |
|||
|
|||
@Async |
|||
public void sendWxMessage(WxConstant.MiniMessageType messageType, String indexPage, String openId, List<String> params) { |
|||
log.info("ExternalService-SendWxMessage:{},{},{},{}", messageType, indexPage, openId, params); |
|||
String gzhUrl = String.format(WxConstant.MESSAGE_TEMPLATE_SEND, getAccessToken()); |
|||
Object o = GetMessageTypeClass(messageType, openId, indexPage, params); |
|||
|
|||
String body = HttpRequest.post(gzhUrl).body(JSON.toJSONString(o)) |
|||
.timeout(5000).execute().body(); |
|||
log.info("审核消息发送结果:{}", body); |
|||
} |
|||
|
|||
public Object GetMessageTypeClass(WxConstant.MiniMessageType messageType, String toUser, String page, List<String> params) { |
|||
switch (messageType) { |
|||
case Audit: { |
|||
} |
|||
default: { |
|||
break; |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
|
|||
public static String getAccessToken() { |
|||
JSONObject jsonObject = new JSONObject(); |
|||
jsonObject.put("appid", "wxd3376bd21c4d12cb"); |
|||
jsonObject.put("secret", "f7b2bf60a9da8691bc148d70ad4ebdb4"); |
|||
jsonObject.put("grant_type", "client_credential"); |
|||
|
|||
|
|||
String body = HttpRequest.post("https://api.weixin.qq.com/cgi-bin/stable_token") |
|||
.body(jsonObject.toJSONString()) |
|||
.execute().body(); |
|||
log.info("getAccessToken: {}", body); |
|||
return JSONObject.parseObject(body).getString("access_token"); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue