《果然新鲜》电商项目(18)- 项目整合WxJava

1.引言

在上一节《果然新鲜电商项目(17)- 搭建企业级微信公众号》,主要讲解如何搭建微信公众号,以及WxJava 案例的使用。

本文开始讲解如何把WxJava框架整合到我们的项目。

2.微信公众号开发原理

在上一篇博客,我们从使用了《weixin-java-mp-demo-springboot》案例来调用了测试了微信公众号,现在我们要整合到我们的项目,步骤如下:

step1:微信服务模块(guoranxinxian-shop-service-weixin)引入Maven依赖:

<dependency>
    <groupId>com.github.binarywang</groupId>
    <artifactId>weixin-java-mp</artifactId>
    <version>3.3.0</version>
</dependency>

step2:配置application.yml,直接从上一篇博客的配置文件复制过来,我是配置到Apollo分布式配置中心的:

wx:
  mp:
    configs:
      - appId: wx???95 #(一个公众号的appid)
        secret: bb42????1c3 #(公众号的appsecret)
        token: ylw666 #(接口配置里的Token值)
        #aesKey:  111(接口配置里的EncodingAESKey值)

在这里插入图片描述
step3:直接复制《weixin-java-mp-demo-springboot》案例的这几个目录到微信服务模块。
在这里插入图片描述
step4 :启动项目,接下来进行测试

3. 测试

3.1 测试接口配置信息

启动项目,微信公众号里点击提交:
在这里插入图片描述
在这里插入图片描述

2.1 发送消息测试

平台会报错,报错内容为:

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: com.thoughtworks.xstream.XStream.setupDefaultSecurity(Lcom/thoughtworks/xstream/XStream;)V] with root cause

在这里插入图片描述
原因是微信框架引入了xstream的版本为1.4.1springCloudeureka-client也引入了xstream为了1.4.9从而版本有冲突。修改依赖的代码:

 <dependency>
 <groupId>com.github.binarywang</groupId>
     <artifactId>weixin-java-mp</artifactId>
     <version>3.3.0</version>
     <exclusions>
         <exclusion>
             <artifactId>xstream</artifactId>
             <groupId>com.thoughtworks.xstream</groupId>
         </exclusion>
     </exclusions>
 </dependency>

 <dependency>
     <groupId>org.springframework.cloud</groupId>
     <artifactId>
         spring-cloud-starter-netflix-eureka-client
     </artifactId>
     <exclusions>
         <exclusion>
             <artifactId>xstream</artifactId>
             <groupId>com.thoughtworks.xstream</groupId>
         </exclusion>
     </exclusions>
 </dependency>

 <dependency>
     <artifactId>xstream</artifactId>
     <groupId>com.thoughtworks.xstream</groupId>
     <version>1.4.10</version>
 </dependency>

再次发送消息,可以消息发送成功,有回复。
在这里插入图片描述

4.总结

注意:导入我的项目时,可能报错,但是却正常运行,这是由于项目使用了Lombok插件,需要先在IDEA里添加Lombok插件,具体的自己百度!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

熊猫-IT

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值