<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      微信公眾號開發接入

      微信公眾號開發

      準備工作

      你要有一個微信公眾號,一個內網穿透工具

      相關網站

      需要資料

      • 服務器配置:設置與開發-->基本配置-->服務器配置
      • token:3-32字符,自己生成配置到服務器配置
      • 公網 IP:云服務器一般都有公網IP
      • 內網穿透工具:本地測試需要穿透,否則無法對接。花生殼、natapp 等自行百度

      注意事項

      1. 請求URL超時,說明內網穿透有問題
      2. 微信驗證消息和推送消息事件接口是同一地址,驗證消息是GET請求 ,事件推送消息是POST
      3. 驗證成功接口需要給微信原樣返回隨機字符串(echostr)內容,否則配置失敗
      4. 響應類型(Content-Type) 一定要是 text/plan
      5. 切記自己對接的系統要是有權鑒,一定要放行微信消息驗證接口

      代碼示例

      消息驗證

      public void pushGet(HttpServletRequest request, HttpServletResponse response) {
          String signature = request.getParameter("signature"); // 簽名
          String echostr = request.getParameter("echostr"); // 隨機字符串
          String timestamp = request.getParameter("timestamp"); // 時間戳
          String nonce = request.getParameter("nonce"); // 隨機數
          log.debug("signature:{}", signature);
          log.debug("echostr:{}", echostr);
          log.debug("timestamp:{}", timestamp);
          log.debug("nonce:{}", nonce);
          System.out.println("signature:" + signature);
          String sha1 = getSHA1(token, timestamp, nonce);
          System.out.println("sha1:" + sha1);
          if (sha1.equals(signature)) {
              log.debug("成功");
              this.responseText(echostr, response);
          }
      }
      

      事件推送

      public void pushPost(HttpServletRequest request, HttpServletResponse response) {
          String signature = request.getParameter("signature"); // 簽名
          String timestamp = request.getParameter("timestamp"); // 時間戳
          String nonce = request.getParameter("nonce"); // 隨機數
          String sha1 = getSHA1(token, timestamp, nonce);
          if (sha1.equals(signature)) {
              Map<String, Object> map = null;
              try {
                  map = XmlUtil.parseXMLToMap(request.getInputStream());
              } catch (IOException e) {
                  e.printStackTrace();
              }
              log.debug("事件消息體:{}", map);
      
              this.responseText("", response); // 回復空串,微信服務器不會對此作任何處理
          }
      
      }
      

      完整代碼

      import io.swagger.annotations.Api;
      import io.swagger.annotations.ApiOperation;
      import lombok.extern.slf4j.Slf4j;
      import org.springframework.web.bind.annotation.*;
      
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      import java.io.IOException;
      import java.io.PrintWriter;
      import java.security.MessageDigest;
      import java.util.*;
      
      /**
       * @description: 微信配置
       * @author: Mr.Fang
       * @create: 2023-05-26
       **/
      @Api(tags = "微信配置")
      @Slf4j
      @RestController
      @RequestMapping("/wx/")
      public class WxController {
      
          String token="78******23";
      
          @ApiOperation(value = "微信 token URL 驗證")
          @GetMapping(value = "push")
          public void pushGet(HttpServletRequest request, HttpServletResponse response) {
              String signature = request.getParameter("signature"); // 簽名
              String echostr = request.getParameter("echostr"); // 隨機字符串
              String timestamp = request.getParameter("timestamp"); // 時間戳
              String nonce = request.getParameter("nonce"); // 隨機數
              log.debug("signature:{}", signature);
              log.debug("echostr:{}", echostr);
              log.debug("timestamp:{}", timestamp);
              log.debug("nonce:{}", nonce);
              System.out.println("signature:" + signature);
              String sha1 = getSHA1(token, timestamp, nonce);
              System.out.println("sha1:" + sha1);
              if (sha1.equals(signature)) {
                  log.debug("成功");
                  this.responseText(echostr, response);
              }
          }
      
          @ApiOperation(value = "接收微信事件")
          @PostMapping(value = "push")
          public void pushPost(HttpServletRequest request, HttpServletResponse response) {
              String signature = request.getParameter("signature"); // 簽名
              String timestamp = request.getParameter("timestamp"); // 時間戳
              String nonce = request.getParameter("nonce"); // 隨機數
              String sha1 = getSHA1(token, timestamp, nonce);
              if (sha1.equals(signature)) {
                  Map<String, Object> map = null;
                  try {
                      // input 流返回是 xml 格式 這里轉 map 了
                      map = XmlUtil.parseXMLToMap(request.getInputStream());
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
                  log.debug("事件消息體:{}", map);
      
                  this.responseText("", response); // 回復空串,微信服務器不會對此作任何處理
              }
      
          }
      
          /**
           * 返回響應結果
           *
           * @param text     響應內容
           * @param response
           */
          public void responseText(String text, HttpServletResponse response) {
              response.setCharacterEncoding("UTF-8");
              response.setContentType("text/plan;charset=UTF-8");
              PrintWriter writer = null;
              try {
                  writer = response.getWriter();
              } catch (IOException e) {
                  e.printStackTrace();
              }
              writer.write(text);
              writer.flush();
              writer.close();
          }
      
          /**
           * 用SHA1算法生成安全簽名
           *
           * @param token     票據
           * @param timestamp 時間戳
           * @param nonce     隨機字符串
           * @return 安全簽名
           */
          public String getSHA1(String token, String timestamp, String nonce) {
              try {
                  String[] array = new String[]{token, timestamp, nonce};
                  StringBuffer sb = new StringBuffer();
                  // 字符串排序
                  Arrays.sort(array);
                  for (int i = 0; i < 3; i++) {
                      sb.append(array[i]);
                  }
                  String str = sb.toString();
                  // SHA1簽名生成
                  MessageDigest md = MessageDigest.getInstance("SHA-1");
                  md.update(str.getBytes());
                  byte[] digest = md.digest();
      
                  StringBuffer hexstr = new StringBuffer();
                  String shaHex = "";
                  for (int i = 0; i < digest.length; i++) {
                      shaHex = Integer.toHexString(digest[i] & 0xFF);
                      if (shaHex.length() < 2) {
                          hexstr.append(0);
                      }
                      hexstr.append(shaHex);
                  }
                  return hexstr.toString();
              } catch (Exception e) {
                  e.printStackTrace();
              }
              return null;
          }
      
      }
      
      

      響應結果

      消息驗證

      signature:207e05105427e1203e769245b3860212c0ffcc56
      echostr:5692172970033782203
      timestamp:1685068850
      nonce:499790541
      signature:207e05105427e1203e769245b3860212c0ffcc56
      sha1:207e05105427e1203e769245b3860212c0ffcc56
      成功
      

      事件推送

      打開公眾號發送消息,接口就可以獲取到推送事件消息內容了

      {"Content":"嘻嘻嘻","CreateTime":"1685068967","ToUserName":"gh_2121212a95","FromUserName":"333333333nSg8OlaSuB0d-f8FKZo","MsgType":"text","MsgId":"24124387253374797"}
      

      其他信息

      公眾號配置

      內網穿透

      posted @ 2023-05-26 10:58  天葬  閱讀(856)  評論(2)    收藏  舉報
      主站蜘蛛池模板: 久久久久久综合网天天| 中国性欧美videofree精品| 国产伦视频一区二区三区| 四虎精品视频永久免费| 激情人妻中出中文字幕一区 | 国内不卡一区二区三区| 艳妇臀荡乳欲伦69调教视频| 久久精品人妻无码一区二区三区| 国产精品色哟哟成人av| 丝袜欧美视频首页在线| 国产午夜A理论毛片| 浓毛老太交欧美老妇热爱乱| 疯狂做受xxxx高潮欧美日本| 亚洲欧美电影在线一区二区| 99国精品午夜福利视频不卡99 | аⅴ天堂中文在线网| 伊人久久大香线蕉综合影院首页 | 精品国产成人网站一区在线| 亚洲国产精品ⅴa在线观看| 亚洲一区二区三区av激情| 天堂亚洲免费视频| 日韩人妻无码一区二区三区99| 国产99在线 | 免费| 人妻中文字幕亚洲精品| 亚洲一区二区约美女探花| 亚洲欧美综合在线天堂| 五月婷婷久久中文字幕| 18禁网站免费无遮挡无码中文| 亚洲日本中文字幕天天更新| 亚洲女同精品中文字幕| 国产一区二区三区我不卡| 亚洲日本韩国欧美云霸高清| 狠狠色综合久久狠狠色综合| 精品无码成人片一区二区98| 国产自在自线午夜精品| 亚洲精品成人区在线观看 | 亚洲精品一区国产欧美| 亚洲国产日韩欧美一区二区三区| 亚洲国产午夜精品理论片| 大帝AV在线一区二区三区| 亚洲综合区激情国产精品|