Java对接模板消息推送笔记
⼀、⾸先想要对接,先要⼀个,再就是开发⽂档了:
developers.weixin.qq/doc/offiaccount/Getting_Started/Overview.html
!!请注意红⾊标记住,这⼀点
⼆、接下来完成的基本配置:
2、令牌(Token):必须为英⽂或数字,长度为3-32字符。上⾯说过做验证的
开发程序3、消息加解密密钥:可以直接随机⽣成
4、消息加解密⽅式:明⽂、兼容、安全 看业务需求选择:我觉得明⽂省事点(个⼈见解)
三、如果⼀直⽤的接⼝调⽤,会有点⿇烦
所以这边我就引⽤了 —》WxJava《—
四、参数说明
五、openId怎么拿?不知道!那好吧,度娘⼀下、google⼀下,疑惑不就解决了!
六、template_id:模板Id;对于这个可以⾃⼰申请 or 选⽤已有的任意选择⼀个进去添加模板就⾏了:
七、现在就开始,请⼤家详细的看看 WxJava 的⽂档
—先建⽴ SpringBoot 项⽬—
1、导⼊wxjava 对应的pom
<!-- WxJava -->
<dependency >
<groupId >com .github .binarywang </groupId >
<artifactId >weixin -java -mp </artifactId >
<version >3.6.0</version >
</dependency >
2、配置相关的信息了,在 .yml或者 .properties⾥⾯配置
wx:
appid: 11111
secret: 22222
token: 33333
aeskey: 44444
或者
wx.appid=123456789
wx.secret=123456789
wx.aeskey=123456789
3、配置了这个就需要对应这个配置的Component了(实体类)
/**
* @ClassName WXProperties
* @Author 晓航仔
* @Date 2021/1/20 04:26
**/
@Data
@Component
@ConfigurationProperties(prefix = "wx")
public class WxMpProperties {
/**
* appId
*/
private String appId;
/**
* appSecret
*/
private String secret;
/**
* token
*/
private String token;
/**
* aesKey
*/
private String aesKey;
}
4、关于注解详情,看官⽅⽂档
SpringBoot:
docs.spring.io/spring-boot/docs/2.2.4.RELEASE/reference/html/spring-boot-features.html#boot-features-external-config-yaml Lombok:
/features/all
-----------------------------JAVA源码 ---------Start-----------------------------
5、模板数据详情以及分析
刚刚选择的模板,这些key都⼀个⼀个参数,⽂档上⾯说的很明⽩,赋值替换就ok了。
6、继续查看 WxJava⽂档
根据上⾯的⽰例代码,写了个⾃测源码Demo