当前位置:   article > 正文

java进行微信公众号开发_binarywang对接公众号

binarywang对接公众号

一、文档

微信官方公众号:微信公众平台开发概述 | 微信开放文档

公众号测试号申请地址:微信公众平台

WxJava公众号开发文档:https://github.com/Wechat-Group/WxJava/wiki/%E5%85%AC%E4%BC%97%E5%8F%B7%E5%BC%80%E5%8F%91%E6%96%87%E6%A1%A3

二、依赖

  1. <dependency>
  2. <groupId>com.github.binarywang</groupId>
  3. <artifactId>wx-java-mp-spring-boot-starter</artifactId>
  4. <version>4.0.0</version>
  5. </dependency>

三、wxjava官方demo

https://github.com/binarywang/wx-java-mp-demo

1.配置

  1. # 公众号配置(必填)
  2. wx.mp.appId=appId
  3. wx.mp.secret=@secret
  4. wx.mp.token=@token
  5. wx.mp.aesKey=@aesKey
  6. # 存储配置redis(可选)
  7. wx.mp.config-storage.type=RedisTemplate
  8. wx.mp.config-storage.key-prefix=wx
  9. wx.mp.config-storage.redis.host=127.0.0.1
  10. wx.mp.config-storage.redis.port=6379
  11. # http客户端配置
  12. wx.mp.config-storage.http-client-type=HttpClient
  13. wx.mp.config-storage.http-proxy-host=
  14. wx.mp.config-storage.http-proxy-port=
  15. wx.mp.config-storage.http-proxy-username=
  16. wx.mp.config-storage.http-proxy-password=

2.案例

  1. package com.binarywang.demo.wx.mp;
  2. import me.chanjar.weixin.common.error.WxErrorException;
  3. import me.chanjar.weixin.mp.api.WxMpService;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.boot.SpringApplication;
  6. import org.springframework.boot.autoconfigure.SpringBootApplication;
  7. import org.springframework.web.bind.annotation.GetMapping;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import org.springframework.web.bind.annotation.RestController;
  10. /**
  11. * @author binary wang
  12. */
  13. @RestController
  14. @RequestMapping("/")
  15. @SpringBootApplication
  16. public class DemoApplication {
  17. public static void main(String[] args) {
  18. SpringApplication.run(DemoApplication.class, args);
  19. }
  20. @Autowired
  21. private WxMpService mpService;
  22. @GetMapping("/test")
  23. public String test() throws WxErrorException {
  24. // this.mpService.getWxMpConfigStorage().getAppId();
  25. return this.mpService.getAccessToken();
  26. }
  27. }

四、详细案例参考官方

https://github.com/Wechat-Group/WxJava/tree/develop/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/神奇cpp/article/detail/874202
推荐阅读
相关标签
  

闽ICP备14008679号