How to configure a single Mini Program using weixin-java-miniapp
This article mainly introduces how to use weixin-java-miniapp to configure a single Mini Program related knowledge, the content is detailed and easy to understand, simple and quick operation, has a certain reference value, I believe you will have something to gain after reading this article on how to use weixin-java-miniapp to configure a single Mini Program, let's take a look at it.
In the development of Mini Program back-end interface, using the weixin-java-miniapp module in weixin-java-tools can often get twice the result with half the effort.
Introduction of weixin-java-tools
Add the following configuration items to the dependency in maven:
Com.github.binarywang weixin-java-miniapp 3.3.0
Add the following configuration items to gradle:
Compile ("com.github.binarywang:weixin-java-miniapp:3.3.0")
Note: the above version I use is 3.3.0, which actually depends on the version you want to use.
Configuration file
There are four main configuration parameters in the configuration file, which are:
AppId
Secret
Token
AesKey
Configuration initialization:
Weixin-java-miniapp can be configured using annotations as follows:
Create the WxMaConfiguration class in the config package.
Use the @ Configuration annotation to configure Mini Program-related parameters, please refer to the following code.
The code example shows a single Mini Program configuration example. If you need to configure multiple Mini Program parameters, please refer to the official case and click to enter.
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;@Configurationpublic class WxMaConfiguration {/ / the way to get the configuration here can be changed to your own way, or you can get the configuration by annotations and so on. 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;}}
Start using
Where you need to use Mini Program-related APIs, you only need to obtain the wxMaService through the static method getWxMaService () in the configuration class, such as:
/ / get Mini Program service instance WxMaService wxMaService = WxMaConfiguration.getWxMaService (); / / get Mini Program QR code generation instance WxMaQrcodeService wxMaQrcodeService = wxMaService.getQrcodeService (); / / you can start to use wxMaQrcodeService for QR code related processing. This is the end of the article on "how to configure a single Mini Program with weixin-java-miniapp". Thank you for reading! I believe that everyone has a certain understanding of "how to use weixin-java-miniapp to configure a single Mini Program" knowledge, if you want to learn more knowledge, welcome to follow the industry information channel.