欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用weixin-java-miniapp配置進行單個小程序的配置詳解

 更新時間:2019年03月29日 09:18:33   作者:yangzhao  
這篇文章主要介紹了使用weixin-java-miniapp配置進行單個小程序的配置詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

在進行小程序后端接口開發(fā)方面,使用weixin-java-tools中的weixin-java-miniapp模塊,往往可以事半功倍。

引入weixin-java-tools

https://mvnrepository.com/中搜索weixin-java-miniapp,進入微信小程序 Java SDK這個項目中。

選擇相應(yīng)正式版本來進行使用。

maven中在依賴中添加如下配置項:

<dependency>
 <groupId>com.github.binarywang</groupId>
 <artifactId>weixin-java-miniapp</artifactId>
 <version>3.3.0</version>
</dependency>

gradle中添加如下配置項:

compile("com.github.binarywang:weixin-java-miniapp:3.3.0")

注意:以上我用的版本是3.3.0,實際中根據(jù)你要使用的版本來用。

配置文件

配置文件中主要配置四項參數(shù),分別是:

  • appId
  • secret
  • token
  • aesKey

配置初始化:

weixin-java-miniapp可以使用注解來進行配置,具體步驟如下:

在config包中創(chuàng)建WxMaConfiguration類。

使用@Configuration注解來進行小程序相關(guān)的參數(shù)配置,可參考以下代碼。

該代碼示例中是單個小程序配置示例,如果需要配置多個小程序的參數(shù),請參考官方案例點擊進入。

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

開始使用

在需要使用小程序相關(guān)接口的地方,只需要通過該配置類中的靜態(tài)方法getWxMaService()來獲取到wxMaService即可開始使用,如:

 // 獲取小程序服務(wù)實例
WxMaService wxMaService = WxMaConfiguration.getWxMaService();
// 獲取小程序二維碼生成實例
WxMaQrcodeService wxMaQrcodeService = wxMaService.getQrcodeService();
// 便可以開始使用wxMaQrcodeService來進行二維碼相關(guān)的處理了
....

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論