记得上下班打卡 | git大法好,push需谨慎

Commit da3c0a0d authored by jiangxiulong's avatar jiangxiulong

迁移adam platform微信 改变关注模版消息内容

parent 42ef0efc
...@@ -18,10 +18,11 @@ public class WechatMpConfigure { ...@@ -18,10 +18,11 @@ public class WechatMpConfigure {
private static String tokenZhengzai; private static String tokenZhengzai;
private static String aeskeyZhengzai; private static String aeskeyZhengzai;
private static String appidModernsky;
private static String secretModernsky;
@Value("${liquidnet.wechat.service.zhengzai.appid}") @Value("${liquidnet.wechat.service.zhengzai.appid}")
public void setAppidZhengzai(String appidZhengzai) { public void setAppidZhengzai(String appidZhengzai) { WechatMpConfigure.appidZhengzai = appidZhengzai; }
WechatMpConfigure.appidZhengzai = appidZhengzai;
}
@Value("${liquidnet.wechat.service.zhengzai.secret}") @Value("${liquidnet.wechat.service.zhengzai.secret}")
public void setSecretZhengzai(String secretZhengzai) { public void setSecretZhengzai(String secretZhengzai) {
WechatMpConfigure.secretZhengzai = secretZhengzai; WechatMpConfigure.secretZhengzai = secretZhengzai;
...@@ -35,7 +36,17 @@ public class WechatMpConfigure { ...@@ -35,7 +36,17 @@ public class WechatMpConfigure {
WechatMpConfigure.aeskeyZhengzai = aeskeyZhengzai; WechatMpConfigure.aeskeyZhengzai = aeskeyZhengzai;
} }
@Value("${liquidnet.wechat.service.modernsky.appid}")
public void setAppidModernsky(String appidModernsky) {
WechatMpConfigure.appidModernsky = appidModernsky;
}
@Value("${liquidnet.wechat.service.modernsky.secret}")
public void setSecretModernsky(String secretModernsky) {
WechatMpConfigure.secretModernsky = secretModernsky;
}
private WxMpService wxMpZhengzaiService; private WxMpService wxMpZhengzaiService;
private WxMpService wxMpModernskyService;
@Autowired @Autowired
private StringRedisTemplate stringRedisTemplate; private StringRedisTemplate stringRedisTemplate;
...@@ -52,12 +63,29 @@ public class WechatMpConfigure { ...@@ -52,12 +63,29 @@ public class WechatMpConfigure {
wxMpDefaultConfig.setToken(tokenZhengzai); wxMpDefaultConfig.setToken(tokenZhengzai);
wxMpDefaultConfig.setAesKey(aeskeyZhengzai); wxMpDefaultConfig.setAesKey(aeskeyZhengzai);
this.setWxMpConfigStorage(wxMpDefaultConfig);
}
};
wxMpModernskyService = new WxMpServiceImpl() {
{
RedisTemplateWxRedisOps redisTemplateWxRedisOps = new RedisTemplateWxRedisOps(stringRedisTemplate);
WxMpRedisConfigImpl wxMpDefaultConfig = new WxMpRedisConfigImpl(redisTemplateWxRedisOps, "sweet:accessToken:service:modernsky");
wxMpDefaultConfig.setAppId(appidModernsky);
wxMpDefaultConfig.setSecret(secretModernsky);
this.setWxMpConfigStorage(wxMpDefaultConfig); this.setWxMpConfigStorage(wxMpDefaultConfig);
} }
}; };
} }
public WxMpService getWxMpService() { public WxMpService getWxMpService(Integer pnum) {
return wxMpZhengzaiService; switch (pnum) {
case 1:
return wxMpZhengzaiService;
case 2:
return wxMpModernskyService;
}
return null;
} }
} }
...@@ -6,15 +6,17 @@ import io.swagger.annotations.Api; ...@@ -6,15 +6,17 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@Api(tags = "小程序登陆") @Api(tags = "小程序/公众号登陆相关")
@RestController @RestController
@RequestMapping("/wechatLogin") @RequestMapping("/wechatLogin")
@Slf4j
public class SweetWechatLoginController { public class SweetWechatLoginController {
@Autowired @Autowired
...@@ -37,4 +39,24 @@ public class SweetWechatLoginController { ...@@ -37,4 +39,24 @@ public class SweetWechatLoginController {
return sweetLoginService.userInfo(code, encryptedData, iv, type); return sweetLoginService.userInfo(code, encryptedData, iv, type);
} }
@ApiOperation(value = "微信小程序登录凭证校验 获取openid", notes = "这里仅用于获取OPENID使用")
@GetMapping(value = {"maOpenId"})
@ApiImplicitParams({
@ApiImplicitParam(type = "query", dataType = "String", name = "jsCode", value = "微信jsCode", required = true),
@ApiImplicitParam(type = "query", dataType = "Integer", name = "type", value = "1草莓 2五百里 3mdsk 4正在", required = true)
})
public ResponseDto<String> wxaCode2Session(@RequestParam String jsCode, @RequestParam Integer type) {
return sweetLoginService.wxaCode2Session(jsCode, type);
}
@ApiOperation(value = "微信公众号登录 获取openid", notes = "这里仅用于获取OPENID使用")
@GetMapping(value = {"mpOpenId"})
@ApiImplicitParams({
@ApiImplicitParam(type = "query", dataType = "String", name = "code", value = "微信code", required = true),
@ApiImplicitParam(type = "query", dataType = "Integer", name = "type", value = "1草莓 2五百里 3mdsk 4正在", required = true)
})
public ResponseDto<String> wxOauth2AccessToken(@RequestParam String code, @RequestParam Integer type) {
return sweetLoginService.wxOauth2AccessToken(code, type);
}
} }
package com.liquidnet.service.sweet.controller;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.sweet.config.WechatMpConfigure;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.enums.TicketType;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
* 正在 摩登公众号分享
* </p>
*
* @author jiangxiulong
* @since 2021-08-20
*/
@Slf4j
@Api(tags = "正在/摩登公众号分享")
@RestController
@RequestMapping("wechatShareSign")
public class SweetWechatShareController {
@Autowired
WechatMpConfigure wechatMpConfigure;
@GetMapping("/zhengzai")
@ApiOperation("正在微信分享sign")
@ApiImplicitParams({
@ApiImplicitParam(type = "query", dataType = "String", name = "url", value = "url地址 注意 URL 一定要动态获取,不能 hardcode", required = true),
})
public ResponseDto<WxJsapiSignature> zhengzai(@RequestParam String url) {
try {
WxMpService wxMpService = wechatMpConfigure.getWxMpService(1);
log.info("zhengzaiShare-isAccessTokenExpired:[{}] ", wxMpService.getWxMpConfigStorage().isAccessTokenExpired());
log.info("zhengzaiShare-getAccessToken:[{}] ", wxMpService.getWxMpConfigStorage().getAccessToken());
log.info("zhengzaiShare-isTicketExpired:[{}] ", wxMpService.getWxMpConfigStorage().isTicketExpired(TicketType.JSAPI));
log.info("zhengzaiShare-Ticket:[{}] ", wxMpService.getWxMpConfigStorage().getTicket(TicketType.JSAPI));
WxJsapiSignature jsapiSignature = wxMpService.createJsapiSignature(url);
return ResponseDto.success(jsapiSignature);
} catch (Exception e) {
log.error("分享signZhengzaiException", e);
return ResponseDto.success();
}
}
@GetMapping("/modernsky")
@ApiOperation("摩登微信分享sign")
@ApiImplicitParams({
@ApiImplicitParam(type = "query", dataType = "String", name = "url", value = "url地址 注意 URL 一定要动态获取,不能 hardcode", required = true),
})
public ResponseDto<WxJsapiSignature> modernsky(@RequestParam String url) {
try {
WxMpService wxMpService = wechatMpConfigure.getWxMpService(2);
log.info("modernskyShare-isAccessTokenExpired:[{}] ", wxMpService.getWxMpConfigStorage().isAccessTokenExpired());
log.info("modernskyShare-getAccessToken:[{}] ", wxMpService.getWxMpConfigStorage().getAccessToken());
log.info("modernskyShare-isTicketExpired:[{}] ", wxMpService.getWxMpConfigStorage().isTicketExpired(TicketType.JSAPI));
log.info("modernskyShare-Ticket:[{}] ", wxMpService.getWxMpConfigStorage().getTicket(TicketType.JSAPI));
WxJsapiSignature jsapiSignature = wxMpService.createJsapiSignature(url);
return ResponseDto.success(jsapiSignature);
} catch (Exception e) {
log.error("分享signModernskyException", e);
return ResponseDto.success();
}
}
}
...@@ -54,7 +54,7 @@ public class SweetWechatCallbackServiceImpl { ...@@ -54,7 +54,7 @@ public class SweetWechatCallbackServiceImpl {
} }
public String record(String requestBody, String timestamp, String nonce, String encType, String msgSignature) { public String record(String requestBody, String timestamp, String nonce, String encType, String msgSignature) {
WxMpService wxMpService = wechatMpConfigure.getWxMpService(); WxMpService wxMpService = wechatMpConfigure.getWxMpService(1);
String out = null; String out = null;
if (encType == null || encType.isEmpty()) { if (encType == null || encType.isEmpty()) {
// 明文传输的消息 // 明文传输的消息
......
...@@ -7,6 +7,7 @@ import com.liquidnet.commons.lang.util.HttpUtil; ...@@ -7,6 +7,7 @@ import com.liquidnet.commons.lang.util.HttpUtil;
import com.liquidnet.commons.lang.util.JsonUtils; import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.ResponseDto; import com.liquidnet.service.base.ResponseDto;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -60,7 +61,7 @@ public class SweetWechatLoginServiceImpl { ...@@ -60,7 +61,7 @@ public class SweetWechatLoginServiceImpl {
String unionId = sessionInfo.getUnionid(); String unionId = sessionInfo.getUnionid();
String openId = sessionInfo.getOpenid(); String openId = sessionInfo.getOpenid();
HashMap<String,Object> userInfo = CollectionUtil.mapStringObject(); HashMap<String, Object> userInfo = CollectionUtil.mapStringObject();
userInfo.put("unionId", unionId); userInfo.put("unionId", unionId);
userInfo.put("openId", openId); userInfo.put("openId", openId);
userInfo.put("getPhoneNumber", wxMaPhoneNumberInfo.getPhoneNumber()); userInfo.put("getPhoneNumber", wxMaPhoneNumberInfo.getPhoneNumber());
...@@ -85,4 +86,23 @@ public class SweetWechatLoginServiceImpl { ...@@ -85,4 +86,23 @@ public class SweetWechatLoginServiceImpl {
} }
} }
public ResponseDto<String> wxaCode2Session(String jsCode, Integer type) {
try {
WxMaJscode2SessionResult wxMaJscode2SessionResult = sweetWechatService.sessionInfo(jsCode, type);
return ResponseDto.success(wxMaJscode2SessionResult.getOpenid());
} catch (Exception e) {
log.error("wxaCode2SessionError", e);
return ResponseDto.failure();
}
}
public ResponseDto<String> wxOauth2AccessToken(String code, Integer type) {
try {
WxOAuth2AccessToken wxOAuth2AccessToken = sweetWechatService.wxOauth2AccessToken(code, type);
return ResponseDto.success(wxOAuth2AccessToken.getOpenId());
} catch (Exception e) {
log.error("wxaCode2SessionError", e);
return ResponseDto.failure();
}
}
} }
...@@ -32,7 +32,7 @@ public class SweetWechatMpService { ...@@ -32,7 +32,7 @@ public class SweetWechatMpService {
private QueueUtils queueUtils; private QueueUtils queueUtils;
public void userInfo() throws WxErrorException { public void userInfo() throws WxErrorException {
WxMpService wxMpService = wechatMpConfigure.getWxMpService(); WxMpService wxMpService = wechatMpConfigure.getWxMpService(1);
String nextOpenid = ""; String nextOpenid = "";
do { do {
...@@ -93,7 +93,7 @@ public class SweetWechatMpService { ...@@ -93,7 +93,7 @@ public class SweetWechatMpService {
} }
public void getUser(String openId) throws WxErrorException { public void getUser(String openId) throws WxErrorException {
WxMpService wxMpService = wechatMpConfigure.getWxMpService(); WxMpService wxMpService = wechatMpConfigure.getWxMpService(1);
WxMpUser wxMpUser = wxMpService.getUserService().userInfo(openId); WxMpUser wxMpUser = wxMpService.getUserService().userInfo(openId);
log.info("openId:[{}],wxMpUsers:[{}]", openId, wxMpUser); log.info("openId:[{}],wxMpUsers:[{}]", openId, wxMpUser);
......
...@@ -5,8 +5,11 @@ import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; ...@@ -5,8 +5,11 @@ import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo; import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
import com.liquidnet.service.sweet.config.WechatMaConfigure; import com.liquidnet.service.sweet.config.WechatMaConfigure;
import com.liquidnet.service.sweet.config.WechatMpConfigure;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -16,6 +19,9 @@ public class SweetWechatService { ...@@ -16,6 +19,9 @@ public class SweetWechatService {
@Autowired @Autowired
WechatMaConfigure wechatMaConfigure; WechatMaConfigure wechatMaConfigure;
@Autowired
WechatMpConfigure wechatMpConfigure;
public WxMaJscode2SessionResult sessionInfo(String code, Integer anum) throws WxErrorException { public WxMaJscode2SessionResult sessionInfo(String code, Integer anum) throws WxErrorException {
WxMaService wxMaService = wechatMaConfigure.getWxMaService(anum); WxMaService wxMaService = wechatMaConfigure.getWxMaService(anum);
log.info("isAccessTokenExpired:[{}] ", wxMaService.getWxMaConfig().isAccessTokenExpired()); log.info("isAccessTokenExpired:[{}] ", wxMaService.getWxMaConfig().isAccessTokenExpired());
...@@ -33,4 +39,12 @@ public class SweetWechatService { ...@@ -33,4 +39,12 @@ public class SweetWechatService {
return wxMaService.getUserService().getPhoneNoInfo(sessionKey, encryptedData, iv); return wxMaService.getUserService().getPhoneNoInfo(sessionKey, encryptedData, iv);
} }
public WxOAuth2AccessToken wxOauth2AccessToken(String code, Integer type) throws WxErrorException {
WxMpService wxMpService = wechatMpConfigure.getWxMpService(type);
log.info("isAccessTokenExpired:[{}] ", wxMpService.getWxMpConfigStorage().isAccessTokenExpired());
log.info("getAccessToken:[{}] ", wxMpService.getWxMpConfigStorage().getAccessToken());
return wxMpService.getOAuth2Service().getAccessToken(code);
}
} }
...@@ -146,12 +146,12 @@ public class SweetWechatTemplateServiceImpl { ...@@ -146,12 +146,12 @@ public class SweetWechatTemplateServiceImpl {
try { try {
String nowTime = DateUtil.getNowTime(); String nowTime = DateUtil.getNowTime();
if (DateUtil.compareStrDay(nowTime, "2021-08-14 10:00:00") == 1) { if (DateUtil.compareStrDay(nowTime, "2021-08-14 10:00:00") == 1) {
WxMpTemplateMessage templateMessage = getTemplateMessage(templateId, sweetWechatUser.getOpenId(), appletAppid, "pages/webview?query=active"); WxMpTemplateMessage templateMessage = getTemplateMessage(templateId, sweetWechatUser.getOpenId(), appletAppid, "pages/webview?query=lottery");
// 添加模板数据 // 添加模板数据
templateMessage.addData(new WxMpTemplateData("first", "感谢关注「正在现场」服务号。我们是草莓音乐节演出官方票务平台。")) templateMessage.addData(new WxMpTemplateData("first", "感谢关注「正在现场」服务号。我们是草莓音乐节演出官方票务平台。"))
.addData(new WxMpTemplateData("keyword1", "您已成功关注「正在现场」服务号")) .addData(new WxMpTemplateData("keyword1", "您已成功关注「正在现场」服务号"))
.addData(new WxMpTemplateData("keyword2", "4006-310-750")) .addData(new WxMpTemplateData("keyword2", "4006-310-750"))
.addData(new WxMpTemplateData("remark", "点击下方小程序,继续参与「和我最有缘的音乐人」测试")); .addData(new WxMpTemplateData("remark", "点击下方小程序,再次参与「草莓星球来的人」周边抽奖"));
String msgId = sendTmpMsg(templateMessage); String msgId = sendTmpMsg(templateMessage);
} else { } else {
WxMpTemplateMessage templateMessage = getTemplateMessage(templateId, sweetWechatUser.getOpenId(), ""); WxMpTemplateMessage templateMessage = getTemplateMessage(templateId, sweetWechatUser.getOpenId(), "");
...@@ -210,7 +210,7 @@ public class SweetWechatTemplateServiceImpl { ...@@ -210,7 +210,7 @@ public class SweetWechatTemplateServiceImpl {
String msgId = null; String msgId = null;
try { try {
// 发送模板消息 // 发送模板消息
WxMpService wxMpService = wechatMpConfigure.getWxMpService(); WxMpService wxMpService = wechatMpConfigure.getWxMpService(1);
log.info("sendTmpMsg-isAccessTokenExpired:[{}] ", wxMpService.getWxMpConfigStorage().isAccessTokenExpired()); log.info("sendTmpMsg-isAccessTokenExpired:[{}] ", wxMpService.getWxMpConfigStorage().isAccessTokenExpired());
log.info("sendTmpMsg-getAccessToken:[{}] ", wxMpService.getWxMpConfigStorage().getAccessToken()); log.info("sendTmpMsg-getAccessToken:[{}] ", wxMpService.getWxMpConfigStorage().getAccessToken());
msgId = wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage); msgId = wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment