在进行小程序后端接口开发方面,使用weixin-java-tools中的weixin-java-miniapp模块,往往可以事半功倍。
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-miniapp</artifactId>
<version>3.3.0</version>
</dependency>
compile("com.github.binarywang:weixin-java-miniapp:3.3.0")
配置文件中主要配置四项参数,分别是:
package com.diboot.miniapp.config;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.WxMaInMemoryConfig;
import dibo.framework.config.BaseConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class WxMaConfiguration {
// 此处获取配置的方式可以改成你自己的方式,也可以注解等方式获取配置等。
private static final String appId = BaseConfig.getProperty("wechat.appId");
private static final String secret = BaseConfig.getProperty("wechat.secret");
private static final String token = BaseConfig.getProperty("wechat.token");
private static final String aesKey = BaseConfig.getProperty("wechat.aesKey");
private static WxMaService wxMaService = null;
@Bean
public Object services(){
WxMaInMemoryConfig config = new WxMaInMemoryConfig();
config.setAppid(appId);
config.setSecret(secret);
config.setToken(token);
config.setAesKey(aesKey);
wxMaService = new WxMaServiceImpl();
wxMaService.setWxMaConfig(config);
return Boolean.TRUE;
}
public static WxMaService getWxMaService(){
return wxMaService;
}
}
// 获取小程序服务实例 WxMaService wxMaService = WxMaConfiguration.getWxMaService(); // 获取小程序二维码生成实例 WxMaQrcodeService wxMaQrcodeService = wxMaService.getQrcodeService(); // 便可以开始使用wxMaQrcodeService来进行二维码相关的处理了 ....