国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

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

2024-05-06 15:41:17
字體:
來源:轉載
供稿:網友

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

引入weixin-java-tools

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

選擇相應正式版本來進行使用。

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,實際中根據你要使用的版本來用。

配置文件

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

appId secret token aesKey

配置初始化:

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

在config包中創建WxMaConfiguration類。

使用@Configuration注解來進行小程序相關的參數配置,可參考以下代碼。

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

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 { // 此處獲取配置的方式可以改成你自己的方式,也可以注解等方式獲取配置等。 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; }}

開始使用

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

 // 獲取小程序服務實例WxMaService wxMaService = WxMaConfiguration.getWxMaService();// 獲取小程序二維碼生成實例WxMaQrcodeService wxMaQrcodeService = wxMaService.getQrcodeService();// 便可以開始使用wxMaQrcodeService來進行二維碼相關的處理了....            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 福州市| 巨鹿县| 普宁市| 桦川县| 江都市| 乐亭县| 商丘市| 怀安县| 延寿县| 新郑市| 汶上县| 临沂市| 永泰县| 东平县| 桃园县| 闻喜县| 扬中市| 武川县| 繁峙县| 二手房| 科技| 亚东县| 社旗县| 墨玉县| 江都市| 青河县| 台中县| 新田县| 本溪| 呼图壁县| 北碚区| 荥经县| 凤冈县| 县级市| 永济市| 遵义县| 南安市| 福海县| 嘉荫县| 林口县| 通许县|