亚洲精品久久久久久第一页-人妻少妇精彩视品一区二区三区-91国产自拍免费视频-免费一级a在线播放视频正片-少妇天天日天天射天天爽-国产大屁股喷水视频在线观看-操美女骚穴抽插性爱视频-亚洲 欧美 中文字幕 丝袜-成人免费无码片在线观看

條形碼掃描器在線使用 二維碼掃描在線識別


條形碼掃描器在線使用 二維碼掃描在線識別

文章插圖
上一章介紹了通過分享好友實現微信跳轉,這一章將介紹通過掃碼實現微信跳轉 。
前提:從微信公眾號那邊獲取appid,secret,grantType三個參數備用 。
1、獲取微信跳轉鏈接接口該接口主要是獲取能重定向到掃碼后頁面的接口鏈接 。
@GET@Path(value = "https://www.520longzhigu.com/diannao/getData")@Produces(MediaType.APPLICATION_JSON)public Response getData() {Map<String, String> result = new HashMap<>();try {//......業(yè)務代碼......String recUrl = "https://XXXX.com/項目名/oauth";//實現重定向的連接,該接口實現看第3節(jié)講result.put("url", recUrl);return Response.ok(result).build();} catch (Exception e) {result.put("code", 0);result.put("msg", "異常");return Response.ok(result).build();} } 2、二維碼頁面該頁面可以通過掃碼進行跳轉,或者復制鏈接在微信中打開實現跳轉 。
<input style="width: 1px;height: 1px;" id="url" value="" type="text" /><div id="root"><div id="pic"><div id="Code"></div></div><div id="txt">掃碼跳轉或者識別圖片跳轉</div><div id="copyLink">復制鏈接(微信中點擊鏈接可直接跳轉)</div></div>function convertCanvasToImage() {var image = new Image();var canvas = document.getElementsByTagName('canvas')[0];image.src = https://www.520longzhigu.com/diannao/canvas.toDataURL("image/png");return image;}$(function() {//可以直接復制鏈接在微信中,然后點擊鏈接可跳轉到與掃碼的同一個界面var url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+ appid + "&redirect_uri=" + linkUrl; //linkUrl是后臺getData方法的url+"&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";$("#url").val( url);$("#pic").qrcode({render: "canvas", //table方式width: 170, //寬度height: 170, //高度text: url //任意內容});var img = convertCanvasToImage();$("canvas").remove();$('#Code').append(img);$("#copyLink").click(function() {var copyText = $("#url");copyText.select();//選擇document.execCommand("Copy");//執(zhí)行復制alert("復制成功!");})});微信自動調用oauth2/authorize接口,運行完接口后得到一次性的code,會自動重定向到redirect_uri?code=XXX&response_type=code&scope=snsapi_base&state=STATE&connect_redirect=1#wechat_redirect
3、跳轉的oauth接口該接口可通過一次性的code獲取用戶的openId,然后重定向到掃碼后的頁面 。(微信會兩次回調這個接口,第一次的code是有值的,第二次code為空!)
@GET@Path(value = "https://www.520longzhigu.com/diannao/oauth")public void oauth(@Context HttpServletResponse httpResponse, @QueryParam("code") String code) {String indexUrl = "https://XXXX.com/項目名/ProduceDeatil.html"; //微信掃碼跳轉的頁面String wxUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=%s";wxUrl = String.format(wxUrl, appId, secret, code, grantType);String response = HttpUtil.sendGet(wxUrl);if (response == null) {logger.error("微信access_token接收失敗");return;}JSONObject jsonObject = JSONObject.parseObject(response);String openid = (String) jsonObject.get("openid");try {httpResponse.sendRedirect(indexUrl + "?openid=" + openid);} catch (IOException e) {e.printStackTrace();}}


    以上關于本文的內容,僅作參考!溫馨提示:如遇健康、疾病相關的問題,請您及時就醫(yī)或請專業(yè)人士給予相關指導!

    「愛刨根生活網」www.malaban59.cn小編還為您精選了以下內容,希望對您有所幫助: