Browse Source

1、小程序密钥变更

master
Aug 1 month ago
parent
commit
86a640ef84
6 changed files with 159 additions and 5 deletions
  1. +1
    -1
      admin-pc/.env.development
  2. +2
    -0
      module-base/base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java
  3. +30
    -0
      module-common/src/main/java/org/jeecg/api/controller/ApiMessageController.java
  4. +12
    -0
      module-common/src/main/java/org/jeecg/api/service/ApiMessageService.java
  5. +110
    -0
      module-common/src/main/java/org/jeecg/api/service/impl/ApiMessageServiceImpl.java
  6. +4
    -4
      module-system/src/main/resources/application-dev.yml

+ 1
- 1
admin-pc/.env.development View File

@ -1,5 +1,5 @@
NODE_ENV=development
VUE_APP_API_BASE_URL=http://localhost:8001/popularize-admin/
VUE_APP_API_BASE_URL=http://localhost:8000/popularize-admin/
# VUE_APP_API_BASE_URL=https://popularize-admin.hhlm1688.com/popularize-admin/
VUE_APP_CAS_BASE_URL=http://cas.example.org:8443/cas
VUE_APP_ONLINE_BASE_URL=http://fileview.jeecg.com/onlinePreview


+ 2
- 0
module-base/base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java View File

@ -77,6 +77,8 @@ public class ShiroConfig {
filterChainDefinitionMap.put("/info_common/**", "anon");
filterChainDefinitionMap.put("/applet_post/**", "anon");
filterChainDefinitionMap.put("/config_common/**", "anon");
filterChainDefinitionMap.put("/message_common/**", "anon");


+ 30
- 0
module-common/src/main/java/org/jeecg/api/controller/ApiMessageController.java View File

@ -0,0 +1,30 @@
package org.jeecg.api.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.api.service.ApiMessageService;
import org.jeecg.common.api.vo.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@Api(tags="推广项目-消息推送相关接口")
@RestController
@RequestMapping("/message_common")
@Slf4j
public class ApiMessageController {
@Resource
private ApiMessageService apiMessageService;
//模板消息通知
@ApiOperation(value="模板消息通知")
@GetMapping(value = "/sendTemplateMessage")
public Result<?> sendTemplateMessage(String userId) {
return apiMessageService.sendTemplateMessage(userId);
}
}

+ 12
- 0
module-common/src/main/java/org/jeecg/api/service/ApiMessageService.java View File

@ -0,0 +1,12 @@
package org.jeecg.api.service;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.springframework.web.bind.annotation.GetMapping;
public interface ApiMessageService {
//模板消息通知
public Result<?> sendTemplateMessage(String userId);
}

+ 110
- 0
module-common/src/main/java/org/jeecg/api/service/impl/ApiMessageServiceImpl.java View File

@ -0,0 +1,110 @@
package org.jeecg.api.service.impl;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.jeecg.api.service.ApiMessageService;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.hanHaiMember.entity.HanHaiMember;
import org.jeecg.modules.hanHaiMember.service.IHanHaiMemberService;
import org.jeecg.modules.popularizeOrderTuiLog.service.IPopularizeOrderTuiLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@Service
public class ApiMessageServiceImpl implements ApiMessageService {
private static final String APP_ID = "wx797abcfb479c75ec";
private static final String APP_SECRET = "7f87f7668da3ee1bef7ded80063f99c1";
private static final String TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + APP_ID + "&secret=" + APP_SECRET;
private static final String TEMPLATE_MESSAGE_URL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=";
@Autowired
private IHanHaiMemberService hanHaiMemberService;
//模板消息推送
@Override
public Result<?> sendTemplateMessage(String userId) {
String templateId = "SQd2axWZD7KCw3jkw--tumMz9-cmP_R2FUhJzByxrP8";
HanHaiMember hanHaiMember = hanHaiMemberService.getById(userId);
String openid = hanHaiMember.getAppletOpenid();
try {
String accessToken = getAccessToken2();
if (accessToken != null && !accessToken.isEmpty()) {
this.sendTemplateMessage2(accessToken, openid, templateId, createTemplateData());
return Result.OK("发送成功");
} else {
return Result.error("无法获取Access Token");
}
} catch (Exception e) {
e.printStackTrace();
return Result.error("发送失败:" + e.getMessage());
}
}
public String getAccessToken2() throws IOException {
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpPost httpPost = new HttpPost(TOKEN_URL);
CloseableHttpResponse response = httpClient.execute(httpPost);
String responseString = EntityUtils.toString(response.getEntity());
Map<String, Object> responseMap = new ObjectMapper().readValue(responseString, Map.class);
return (String) responseMap.get("access_token");
}
}
public void sendTemplateMessage2(String accessToken, String toUser, String templateId, Map<String, Object> data) throws IOException {
String url = TEMPLATE_MESSAGE_URL + accessToken;
Map<String, Object> requestBody = new HashMap<>();
requestBody.put("touser", toUser);
requestBody.put("template_id", templateId);
requestBody.put("data", data);
ObjectMapper objectMapper = new ObjectMapper();
String jsonRequest = objectMapper.writeValueAsString(requestBody);
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new StringEntity(jsonRequest, "UTF-8"));
httpPost.setHeader("Content-Type", "application/json");
CloseableHttpResponse response = httpClient.execute(httpPost);
String responseString = EntityUtils.toString(response.getEntity());
System.out.println("Response: " + responseString);
}
}
private Map<String, Object> createTemplateData() {
Map<String, Object> data = new HashMap<>();
data.put("first", new HashMap<String, String>() {{
put("value", "Hello, this is a test message!");
put("color", "#173177");
}});
data.put("keyword1", new HashMap<String, String>() {{
put("value", "Keyword1 Value");
put("color", "#173177");
}});
data.put("keyword2", new HashMap<String, String>() {{
put("value", "Keyword2 Value");
put("color", "#173177");
}});
data.put("remark", new HashMap<String, String>() {{
put("value", "This is a remark.");
put("color", "#173177");
}});
return data;
}
}

+ 4
- 4
module-system/src/main/resources/application-dev.yml View File

@ -342,7 +342,7 @@ third-app:
##配置微信 - 推广项目
wechat-dm:
mpAppId: wx797abcfb479c75ec
mpAppSecret: c4565acc18698a7000be1b2bb748be81
mpAppSecret: 7f87f7668da3ee1bef7ded80063f99c1
mchId: 1659066870
mchKey: vtribevtribevtribevtribevtribe12
keyPath:
@ -366,10 +366,10 @@ wechat-dm:
wx:
miniapp:
appid: wx797abcfb479c75ec # 微信小程序appid
secret: c4565acc18698a7000be1b2bb748be81 # 微信小程序密钥
secret: 7f87f7668da3ee1bef7ded80063f99c1 # 微信小程序密钥
merchantId: 1659066870 # 商户号
privateKeyPath: E:\\file\\2025\\1\\popularize-admin\\module-system\\src\main\\resources\\apiclient_key.pem
# privateKeyPath: /root/api/pem/apiclient_key.pem
# privateKeyPath: module-system/src/main/resources/apiclient_key.pem
privateKeyPath: /root/api/pem/apiclient_key.pem
merchantSerialNumber: 7BE56DC695B2B612BD1C6C710A7FBFA1AC46B10F # 商户API证书序列号
apiV3Key: vtribevtribevtribevtribevtribe12 # 商户APIV3密钥
payNotifyUrl: https://popularize-admin.hhlm1688.com/popularize-admin/order_pay/refundNotify # 支付通知地址(测试环境)


Loading…
Cancel
Save