java进行微信公众号开发

一、文档

微信官方公众号:https://developers.weixin.qq.com/doc/offiaccount/Getting_Started/Overview.html

公众号测试号申请地址:https://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index

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

二、依赖

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

三、wxjava官方demo

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

1.配置

  
# 公众号配置(必填)
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.案例

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();
    }
}

四、详细案例参考官方

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

猜你喜欢

转载自blog.csdn.net/qq_29752857/article/details/114137156