Java for WeChat public account development

1. Document

WeChat official account: https://developers.weixin.qq.com/doc/offiaccount/Getting_Started/Overview.html

Official account test account application address: https://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index

WxJava Official Account Development Document: 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

 

2. Dependence

 <dependency>
    <groupId>com.github.binarywang</groupId>
    <artifactId>wx-java-mp-spring-boot-starter</artifactId>
    <version>4.0.0</version>
 </dependency>

Three, wxjava official demo

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

1. Configuration

  
# 公众号配置(必填)
wx.mp.appId=appId
wx.mp.secret=@secret
wx.mp.token=@token
wx.mp.aesKey=@aesKey
# 存储配置redis(可选)
wx.mp.config-storage.type=RedisTemplate
wx.mp.config-storage.key-prefix=wx
wx.mp.config-storage.redis.host=127.0.0.1
wx.mp.config-storage.redis.port=6379
# http客户端配置
wx.mp.config-storage.http-client-type=HttpClient
wx.mp.config-storage.http-proxy-host=
wx.mp.config-storage.http-proxy-port=
wx.mp.config-storage.http-proxy-username=
wx.mp.config-storage.http-proxy-password=

2. Case

package com.binarywang.demo.wx.mp;

import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author binary wang
 */
@RestController
@RequestMapping("/")
@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @Autowired
    private WxMpService mpService;

    @GetMapping("/test")
    public String test() throws WxErrorException {
        // this.mpService.getWxMpConfigStorage().getAppId();
        return  this.mpService.getAccessToken();
    }
}

Fourth, the detailed case reference official

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

Guess you like

Origin blog.csdn.net/qq_29752857/article/details/114137156