以下代码基于 weixin-java-mp:4.0.0
|
小程序 |
公众号 |
|
wx:
ma:
xxx:
appId: 开发者ID
secret: 开发者密码
msgDataFormat: JSON
|
wx:
mp:
xxx:
appId: 开发者ID
secret: 开发者密码
token: 令牌
aesKey: 消息加解密密钥
|
|
@Data
@ConfigurationProperties(prefix = "wx.ma.xxx")
public class WxMaConfig implements Serializable {
private static final long serialVersionUID = -7742875304011897963L;
/**
* 设置微信小程序的appId
*/
private String appId;
/**
* 设置微信小程序的Secret
*/
private String secret;
/**
* 消息数据格式
*/
private String msgDataFormat;
}
|
@Data @ConfigurationProperties(prefix = "wx.mp.xxx")
public class WxMpConfig implements Serializable {
/**
* 设置微信小程序的appId
*/
private String appId;
/**
* 设置微信小程序的Secret
*/
private String secret;
/**
* 设置微信小程序消息服务器配置的token
*/
private String token;
/**
* 设置微信小程序消息服务器配置的EncodingAESKey
*/
private String aesKey;
}
|
|
@Bean public WxMaService wxMaService(WxMaConfig wxMaConfig) { WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl(); config.setAppid(wxMaConfig.getAppId()); config.setSecret(wxMaConfig.getSecret()); config.setMsgDataFormat(wxMaConfig.getMsgDataFormat());
WxMaService service = new WxMaServiceImpl(); service.setWxMaConfig(config); return service; }
|
@Bean public WxMpService wxMpService(WxMpConfig wxMpConfig) { WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl(); config.setAppId(wxMpConfig.getAppId()); config.setSecret(wxMpConfig.getSecret()); config.setToken(wxMpConfig.getToken()); config.setAesKey(wxMpConfig.getAesKey());
WxMpService service = new WxMpServiceImpl(); service.setWxMpConfigStorage(config); return service; }
|