久久福利_99r_国产日韩在线视频_直接看av的网站_中文欧美日韩_久久一

您的位置:首頁技術文章
文章詳情頁

Java 微信公眾號開發(fā)相關總結

瀏覽:145日期:2022-05-22 10:59:54
目錄首先必須要有一個個人微信公眾號效果圖后臺路由代碼完整代碼首先必須要有一個個人微信公眾號

個人微信公眾號相關的接口權限有限,不過用于個人學習體驗一下足夠了,如圖:

Java 微信公眾號開發(fā)相關總結

然后進入微信公眾后臺,點擊基本配置,按照如下操作(點擊啟用,相當于設置請求url為自己后臺的):

Java 微信公眾號開發(fā)相關總結

設置服務器URL、令牌、消息加解密密鑰(這個可以使用自動生成的):

Java 微信公眾號開發(fā)相關總結

服務器URL至關重要,我在這里設置為我自己的域名http://www.youcongtech.com/wx-api。

這個wx-api就是后面對應的接口(比如我發(fā)送某個關鍵字,返回對應的信息)。token可以設置復雜點。

效果圖

Java 微信公眾號開發(fā)相關總結

上面的演示效果來自本人微信公眾號,并長期運行穩(wěn)定沒有任何問題。

后臺路由代碼

package com.blog.springboot.controller;import java.io.IOException;import java.io.PrintWriter;import java.io.UnsupportedEncodingException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.PostMapping;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;import com.blog.springboot.wx.service.WxService;import com.blog.springboot.wx.util.SignUtil;import io.swagger.annotations.Api;import io.swagger.annotations.ApiOperation;/** * 微信公眾號API * @author youcong * @date 2019-6-02 */@RestController@RequestMapping('/wx_public_api')@Api(tags = { '微信公眾號api' }, description = '微信公眾號api')public class WxPublicApiController extends AbstractController{@Autowiredprivate WxService wxService; /*** 微信公眾平臺服務器配置驗證* @param request* @param response*/ @GetMapping @ApiOperation('微信公眾平臺服務器配置驗證') public void validate(HttpServletRequest request, HttpServletResponse response) {// 微信加密簽名,signature結合了開發(fā)者填寫的token參數和請求中的timestamp參數、nonce參數。String signature = request.getParameter('signature');// 時間戳String timestamp = request.getParameter('timestamp');// 隨機數String nonce = request.getParameter('nonce');// 隨機字符串String echostr = request.getParameter('echostr');PrintWriter out = null;try { out = response.getWriter(); // 通過檢驗signature對請求進行校驗,若校驗成功則原樣返回echostr,否則接入失敗 if (SignUtil.checkSignature(signature, timestamp, nonce)) {out.print(echostr); }} catch (IOException e) { e.printStackTrace(); logger.error(e.getMessage()); } finally { out.close(); out = null;} } /** * 關注推送消息 * @param request * @param response */ @PostMapping @ApiOperation('關注推送消息') public void about(HttpServletRequest request, HttpServletResponse response) {try { request.setCharacterEncoding('UTF-8');} catch (UnsupportedEncodingException e) { e.printStackTrace(); logger.error(e.getMessage(),e);}response.setContentType('text/html;charset=UTF-8');// 調用核心業(yè)務類接收消息、處理消息String respMessage = wxService.newMessageRequest(request);// 響應消息PrintWriter out = null;try { out = response.getWriter(); out.print(respMessage);} catch (IOException e) { e.printStackTrace(); logger.error(e.getMessage(),e);} finally { out.close(); out = null;} }}完整代碼

完整代碼已經放到我個人的GitHub倉庫,地址為:https://github.com/developers-youcong/blog-springcloud-pro/tree/master/blog-wx-client

這是其中的子項目,功能主要是微信公眾平臺。

鑒于我個人主要維護的開源項目尚未公開,有很多隱私信息等,所以將其中的微信公眾號模塊抽取出來放到我的新開源項目blog-springcloud-pro中(此項目目前處于開發(fā)中)。

微信公眾號模塊基本上換上自己的token、appid、appsecret并部署到線上就基本可用了。有任何問題,可留言。

以上就是Java 微信公眾號開發(fā)相關總結的詳細內容,更多關于Java 微信公眾號開發(fā)的資料請關注好吧啦網其它相關文章!

標簽: 微信
相關文章:
主站蜘蛛池模板: 99视频在线免费观看 | 日韩在线视频免费 | 国产精品毛片一区二区三区 | 精品视频二区 | 亚洲国产视频一区 | 91精品国产综合久久久久久 | 日本大人吃奶视频xxxx | 久久久精彩视频 | av网站在线免费看 | 日韩精品99| 亚洲精品乱码久久久久久国产主播 | 成人免费毛片嘿嘿连载视频 | 欧美日韩精品一区二区三区 | 狠狠草视频 | 新疆少妇videos高潮 | 色视频网站在线观看 | 黄色片网站在线免费观看 | 久久久久久成人 | 日韩中文字幕一区 | 中文字幕亚洲一区二区三区 | 视频国产一区 | 日本久久久久久 | 午夜男人网 | 欧美日韩免费 | 日韩性猛交 | 最新日韩av| 蜜桃视频网站在线观看 | 欧美中文字幕一区二区 | 国产激情偷乱视频一区二区三区 | 国产精品粉嫩白浆在线观看 | 亚洲人成一区 | 国内自拍视频网 | 玖玖精品在线 | 国产极品探花 | 一区二区三区视频 | 国产精品国产 | 久久久国产视频 | 欧美一区二区三区电影 | 日韩一区中文 | 国产精品亚洲视频 | 欧美精品1区2区3区 欧美视频在线一区 |