mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-09-19 18:22:27 +08:00
#379 WxOpenXmlMessage 增加 加密 WxMpXmlOutMessage接口 MpConfigStorage 返回aeskey和token MpService可以直接加密 增加 全网发布用例
* 增加 微信第三方平台 接口 * WxOpenXmlMessage 消息处理 * 增加 摇周边部分接口 * fix * fix * rebase * 增加 摇周边部分接口 * fix * fix * unix 换行符 * fix 三方接口BUG * fix URL 错误 * WxOpenMpServiceImpl 修改为包可见,防止用户混淆 WxOpenXmlMessage 增加 加密 WxMpXmlOutMessage接口 MpConfigStorage 返回aeskey和token MpService可以直接加密 增加 全网发布用例
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
消息机制未实现,下面为通知回调中设置的代码部分
|
||||
|
||||
以下代码可通过腾讯全网发布测试用例
|
||||
```
|
||||
@RestController
|
||||
@RequestMapping("notify")
|
||||
@@ -55,7 +57,31 @@ public class NotifyController extends WechatThridBaseController {
|
||||
// aes加密的消息
|
||||
WxMpXmlMessage inMessage = WxOpenXmlMessage.fromEncryptedMpXml(requestBody, wxOpenService.getWxOpenConfigStorage(), timestamp, nonce, msgSignature);
|
||||
this.logger.debug("\n消息解密后内容为:\n{} ", inMessage.toString());
|
||||
//wxOpenService.getWxOpenComponentService().getWxMpServiceByAppid(appId);
|
||||
// 全网发布测试用例
|
||||
if (StringUtils.equalsAnyIgnoreCase(appId, "wxd101a85aa106f53e", "wx570bc396a51b8ff8")) {
|
||||
try {
|
||||
if (StringUtils.equals(inMessage.getMsgType(), "text")) {
|
||||
if (StringUtils.equals(inMessage.getContent(), "TESTCOMPONENT_MSG_TYPE_TEXT")) {
|
||||
out = new WxOpenCryptUtil(wxOpenService.getWxOpenConfigStorage()).encrypt(
|
||||
WxMpXmlOutMessage.TEXT().content("TESTCOMPONENT_MSG_TYPE_TEXT_callback")
|
||||
.fromUser(inMessage.getToUser())
|
||||
.toUser(inMessage.getFromUser())
|
||||
.build()
|
||||
.toXml()
|
||||
);
|
||||
} else if (StringUtils.startsWith(inMessage.getContent(), "QUERY_AUTH_CODE:")) {
|
||||
String msg = inMessage.getContent().replace("QUERY_AUTH_CODE:", "") + "_from_api";
|
||||
WxMpKefuMessage kefuMessage = WxMpKefuMessage.TEXT().content(msg).toUser(inMessage.getFromUser()).build();
|
||||
wxOpenService.getWxOpenComponentService().getWxMpServiceByAppid(appId).getKefuService().sendKefuMessage(kefuMessage);
|
||||
}
|
||||
} else if (StringUtils.equals(inMessage.getMsgType(), "event")) {
|
||||
WxMpKefuMessage kefuMessage = WxMpKefuMessage.TEXT().content(inMessage.getEvent() + "from_callback").toUser(inMessage.getFromUser()).build();
|
||||
wxOpenService.getWxOpenComponentService().getWxMpServiceByAppid(appId).getKefuService().sendKefuMessage(kefuMessage);
|
||||
}
|
||||
} catch (WxErrorException e) {
|
||||
logger.error("callback", e);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
@@ -29,11 +29,11 @@ public interface WxOpenComponentService {
|
||||
/**
|
||||
* 用code换取oauth2的access token
|
||||
*/
|
||||
String OAUTH2_ACCESS_TOKEN_URL = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&code=%s&grant_type=authorization_code&component_appid=%s";
|
||||
String OAUTH2_ACCESS_TOKEN_URL = "https://api.weixin.qq.com/sns/oauth2/component/access_token?appid=%s&code=%s&grant_type=authorization_code&component_appid=%s";
|
||||
/**
|
||||
* 刷新oauth2的access token
|
||||
*/
|
||||
String OAUTH2_REFRESH_TOKEN_URL = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=%s&grant_type=refresh_token&refresh_token=%s&component_appid==%s";
|
||||
String OAUTH2_REFRESH_TOKEN_URL = "https://api.weixin.qq.com/sns/oauth2/component/refresh_token?appid=%s&grant_type=refresh_token&refresh_token=%s&component_appid==%s";
|
||||
|
||||
WxMpService getWxMpServiceByAppid(String appid);
|
||||
|
||||
|
@@ -329,7 +329,7 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage {
|
||||
|
||||
@Override
|
||||
public String getToken() {
|
||||
return null;
|
||||
return wxOpenConfigStorage.getComponentToken();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -340,7 +340,7 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage {
|
||||
|
||||
@Override
|
||||
public String getAesKey() {
|
||||
return null;
|
||||
return wxOpenConfigStorage.getComponentAesKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -9,7 +9,7 @@ import me.chanjar.weixin.open.api.WxOpenComponentService;
|
||||
/**
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
*/
|
||||
public class WxOpenMpServiceImpl extends WxMpServiceImpl {
|
||||
/* package */ class WxOpenMpServiceImpl extends WxMpServiceImpl {
|
||||
private WxOpenComponentService wxOpenComponentService;
|
||||
private WxMpConfigStorage wxMpConfigStorage;
|
||||
private String appId;
|
||||
|
@@ -5,6 +5,7 @@ import com.thoughtworks.xstream.annotations.XStreamConverter;
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
|
||||
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
|
||||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
|
||||
import me.chanjar.weixin.open.api.WxOpenConfigStorage;
|
||||
import me.chanjar.weixin.open.util.WxOpenCryptUtil;
|
||||
import me.chanjar.weixin.open.util.xml.XStreamTransformer;
|
||||
@@ -52,6 +53,12 @@ public class WxOpenXmlMessage implements Serializable {
|
||||
@XStreamConverter(value = XStreamCDataConverter.class)
|
||||
private String preAuthCode;
|
||||
|
||||
public static String wxMpOutXmlMessageToEncryptedXml(WxMpXmlOutMessage message, WxOpenConfigStorage wxOpenConfigStorage){
|
||||
String plainXml = message.toXml();
|
||||
WxOpenCryptUtil pc = new WxOpenCryptUtil(wxOpenConfigStorage);
|
||||
return pc.encrypt(plainXml);
|
||||
}
|
||||
|
||||
public static WxOpenXmlMessage fromXml(String xml) {
|
||||
//修改微信变态的消息内容格式,方便解析
|
||||
xml = xml.replace("</PicList><PicList>", "");
|
||||
|
Reference in New Issue
Block a user