資源簡介
# 微信生態開發常用接口使用案例
#### 本項目是一個微信生態開發常用接口的案例集合,其中包括:解密小程序code獲取openid,發送小程序模板消息,發送公眾號模板消息,用戶關注、取關公眾號的事件處理等。
#### 擴展知識
openid:一個小程序的每個用戶都有一個唯一的openid,是一個小程序用戶中用戶的唯一身份標志,公眾號也一樣;
unionid:用戶的小程序、公眾號可在微信開放平臺進行關聯,關聯之后的小程序和公眾號有一個相同的unionid,公眾號始終有unionid,小程序如果沒有和公眾號關聯是
沒有unionid的。
### 1.0:微信小程序解密code得到openid([官方文檔](https://developers.weixin.qq.com/miniprogram/dev/api/wx.login.html))
過程如下:
1.前端傳入code到后端;
2.后端解密code得到openid、session_key、unionid(小程序和公眾號關聯后才能解密出unionid)。
### 1.1:發送小程序模板消息([官方文檔](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/template-message.html))
過程如下:
必備知識:發送模板消息到指定用戶需要用戶的formid和openid,formid是用戶進行表單提交時微信生成的一個序列號,有效期為一周,開發者每收集一個用戶的
formid即可以向該用戶發送一次模板消息。
1.收集用戶的formid;
2.向指定用戶發送模板消息。
### 1.2:對微信公眾號進行服務器配置校驗token([參考博客](https://blog.csdn.net/LONG_Yi_1994/article/details/90022307))
過程如下:
如果進行微信公眾號開發,進行服務器配置是必要的,通過配置,用戶與公眾號的事件交互消息將發送至開發者配置的URL上,開發者可在自己寫的接口內進行事件處理。
1.填寫配置信息,確保URL可訪問;
2.開發token驗證接口。
### 1.3:用戶與公眾號事件交互處理(包括用戶關注、取關公眾號事件)
過程如下:
1:用戶關注或取關公眾號后,微信將把事件消息推送至開發者填寫的URL上,開發者可在接口內進行處理,例如:保存用戶openid,依據openid得到unionid等。
### 1.4:發送公眾號模板消息([官方文檔](https://mp.weixin.qq.com/advanced/tmplmsg?action=faq&token=611048160&lang=zh_CN))
過程如下:
1:發送公眾號模板消息和發送小程序模板消息類似,只是發送公眾號模板消息是沒有限制的,有用戶的openid即可發送。
代碼片段和文件信息
/*
Licensed?to?the?Apache?Software?Foundation?(ASF)?under?one
or?more?contributor?license?agreements.??See?the?NOTICE?file
distributed?with?this?work?for?additional?information
regarding?copyright?ownership.??The?ASF?licenses?this?file
to?you?under?the?Apache?License?Version?2.0?(the
“License“);?you?may?not?use?this?file?except?in?compliance
with?the?License.??You?may?obtain?a?copy?of?the?License?at
??https://www.apache.org/licenses/LICENSE-2.0
Unless?required?by?applicable?law?or?agreed?to?in?writing
software?distributed?under?the?License?is?distributed?on?an
“AS?IS“?BASIS?WITHOUT?WARRANTIES?OR?CONDITIONS?OF?ANY
KIND?either?express?or?implied.??See?the?License?for?the
specific?language?governing?permissions?and?limitations
under?the?License.
*/
import?java.io.File;
import?java.io.F
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2019-06-06?02:07??wxutils-master\
?????文件?????????303??2019-06-06?02:07??wxutils-master\.gitignore
?????目錄???????????0??2019-06-06?02:07??wxutils-master\.mvn\
?????目錄???????????0??2019-06-06?02:07??wxutils-master\.mvn\wrapper\
?????文件????????4629??2019-06-06?02:07??wxutils-master\.mvn\wrapper\MavenWrapperDownloader.java
?????文件???????48337??2019-06-06?02:07??wxutils-master\.mvn\wrapper\maven-wrapper.jar
?????文件?????????116??2019-06-06?02:07??wxutils-master\.mvn\wrapper\maven-wrapper.properties
?????文件????????2549??2019-06-06?02:07??wxutils-master\README.md
?????文件????????9114??2019-06-06?02:07??wxutils-master\mvnw
?????文件????????5811??2019-06-06?02:07??wxutils-master\mvnw.cmd
?????文件????????4687??2019-06-06?02:07??wxutils-master\pom.xm
?????目錄???????????0??2019-06-06?02:07??wxutils-master\src\
?????目錄???????????0??2019-06-06?02:07??wxutils-master\src\main\
?????目錄???????????0??2019-06-06?02:07??wxutils-master\src\main\java\
?????目錄???????????0??2019-06-06?02:07??wxutils-master\src\main\java\com\
?????目錄???????????0??2019-06-06?02:07??wxutils-master\src\main\java\com\longdatech\
?????目錄???????????0??2019-06-06?02:07??wxutils-master\src\main\java\com\longdatech\decryptcode\
?????文件?????????335??2019-06-06?02:07??wxutils-master\src\main\java\com\longdatech\decryptcode\WxUtils_Application.java
?????目錄???????????0??2019-06-06?02:07??wxutils-master\src\main\java\com\longdatech\decryptcode\controller\
?????文件????????6557??2019-06-06?02:07??wxutils-master\src\main\java\com\longdatech\decryptcode\controller\Ldkj_WxApiController.java
?????目錄???????????0??2019-06-06?02:07??wxutils-master\src\main\java\com\longdatech\decryptcode\service\
?????文件?????????229??2019-06-06?02:07??wxutils-master\src\main\java\com\longdatech\decryptcode\service\LdkjWxApiService.java
?????文件????????5480??2019-06-06?02:07??wxutils-master\src\main\java\com\longdatech\decryptcode\service\LdkjWxApiServiceImpl.java
?????目錄???????????0??2019-06-06?02:07??wxutils-master\src\main\java\com\longdatech\decryptcode\utils\
?????文件???????10814??2019-06-06?02:07??wxutils-master\src\main\java\com\longdatech\decryptcode\utils\CommonUtil.java
?????文件????????6503??2019-06-06?02:07??wxutils-master\src\main\java\com\longdatech\decryptcode\utils\MyHttpRequestUtil.java
?????文件?????????551??2019-06-06?02:07??wxutils-master\src\main\java\com\longdatech\decryptcode\utils\MyX509TrustManager.java
?????文件????????2244??2019-06-06?02:07??wxutils-master\src\main\java\com\longdatech\decryptcode\utils\SignUtil.java
?????文件????????1296??2019-06-06?02:07??wxutils-master\src\main\java\com\longdatech\decryptcode\utils\Swagger2.java
?????文件?????????465??2019-06-06?02:07??wxutils-master\src\main\java\com\longdatech\decryptcode\utils\TemplateData.java
?????文件?????????664??2019-06-06?02:07??wxutils-master\src\main\java\com\longdatech\decryptcode\utils\Token.java
............此處省略11個文件信息
評論
共有 條評論