|
|
@@ -36,11 +36,20 @@ import com.xxl.job.core.context.XxlJobHelper;
|
|
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.PrintWriter;
|
|
|
+import java.security.MessageDigest;
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneOffset;
|
|
|
@@ -790,4 +799,99 @@ public class CusFollowService extends BaseService<CusFollow> {
|
|
|
public ResponseResultVO<List<Map>> selectCusFollow(CusFollowQuery cusFollowQuery) {
|
|
|
return ResponseResultUtil.success(cusFollowMapper.selectCusFollow(cusFollowQuery));
|
|
|
}
|
|
|
+
|
|
|
+ public ResponseResultVO<?> wxMessagePush(HttpServletRequest request) {
|
|
|
+ // 获取微信Token
|
|
|
+ String wxToken = getWxToken();
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ // 接口调用凭证
|
|
|
+ params.put("access_token", wxToken);
|
|
|
+ // 所需下发的订阅模板id
|
|
|
+ params.put("template_id", "z3REuwft6NLPxVW8s5HN1RH_gVxN9KPH7boGh92shYs");
|
|
|
+ // 点击模板卡片后的跳转页面
|
|
|
+ params.put("page", "pages/login/login");
|
|
|
+ // 接收者(用户)的 openid
|
|
|
+ params.put("touser", "oNIC56z-NuTQYlzfnupF_ZEo9agc");
|
|
|
+ // 跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;
|
|
|
+ params.put("miniprogram_state", "developer");
|
|
|
+
|
|
|
+ // 构造对应的显示信息 和模板数据结构对应
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ data.put("time4", createDataItem("value", "2024年07月18日"));
|
|
|
+ data.put("thing1", createDataItem("value", "ly"));
|
|
|
+ data.put("phone_number2", createDataItem("value", "19841226666"));
|
|
|
+ data.put("time7", createDataItem("value", "2024年07月18日"));
|
|
|
+ data.put("thing5", createDataItem("value", "666"));
|
|
|
+ params.put("data", data);
|
|
|
+
|
|
|
+ ResponseResultVO<JSONObject> post = HttpUtils.post("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + wxToken, params);
|
|
|
+ return post;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Map<String, Object> createDataItem(String name, String value) {
|
|
|
+ Map<String, Object> item = new HashMap<>();
|
|
|
+ item.put("value", value);
|
|
|
+ return item;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void wxMessageTest(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ String signature = request.getParameter("signature");
|
|
|
+ String timestamp = request.getParameter("timestamp");
|
|
|
+
|
|
|
+ String nonce = request.getParameter("nonce");
|
|
|
+
|
|
|
+ String echostr = request.getParameter("echostr");
|
|
|
+ // 和小程序后台配置的token保持一致
|
|
|
+ String token = "dPM4EILWQqeEsEmft9pKMIll4VGZ6pJK";
|
|
|
+ // 将下面三个参数拼接成字符串
|
|
|
+ StringBuffer content = new StringBuffer();
|
|
|
+ content.append(timestamp);
|
|
|
+ content.append(nonce);
|
|
|
+ content.append(token);
|
|
|
+ PrintWriter out = null;
|
|
|
+ try {
|
|
|
+ out = response.getWriter();
|
|
|
+ MessageDigest md = MessageDigest.getInstance("SHA-1");
|
|
|
+ // 对拼接好的字符串进行sha1加密
|
|
|
+ byte[] digest = md.digest(content.toString().getBytes());
|
|
|
+ String tmpStr = byteToStr(digest);
|
|
|
+ //获得加密后的字符串与signature对比
|
|
|
+ if (tmpStr != null && tmpStr.equals(signature.toUpperCase())){
|
|
|
+ out.print(echostr);
|
|
|
+ out.flush();
|
|
|
+ }
|
|
|
+ } catch (NoSuchAlgorithmException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ out.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getWxToken(){
|
|
|
+ String appId = config.getAppId();
|
|
|
+ String appSecret = config.getAppSecret();
|
|
|
+ ResponseResultVO<JSONObject> tokenRes = HttpUtils.get("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appId + "&secret=" + appSecret);
|
|
|
+ JSONObject data = tokenRes.getData();
|
|
|
+ return String.valueOf(data.get("access_token"));
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String byteToStr(byte[] byteArray) {
|
|
|
+ String strDigest = "";
|
|
|
+ for (int i = 0; i < byteArray.length; i++) {
|
|
|
+ strDigest += byteToHexStr(byteArray[i]);
|
|
|
+ }
|
|
|
+ return strDigest;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String byteToHexStr(byte mByte) {
|
|
|
+ char[] Digit = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A',
|
|
|
+ 'B', 'C', 'D', 'E', 'F' };
|
|
|
+ char[] tempArr = new char[2];
|
|
|
+ tempArr[0] = Digit[(mByte >>> 4) & 0X0F];
|
|
|
+ tempArr[1] = Digit[mByte & 0X0F];
|
|
|
+ String s = new String(tempArr);
|
|
|
+ return s;
|
|
|
+ }
|
|
|
}
|