微信企业号,测试扫一扫功能

using Senparc.Weixin.HttpUtility;
using Senparc.Weixin.Work.Containers;
using Senparc.Weixin.Work.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace wxwork
{
    public partial class Index : System.Web.UI.Page
    {
        public string Secret = "acO2CkgxxxxqeEWT2IPzdvQxxxxx9H4";
        public string CorpID = "xxx1f3e8axxxbc2ddf";
        public string url = "http://wxt.buynow.com.cn/";


        public long timestamp = 0;
        public string nonceStr = null;
        public string jsapi_ticket = null;
        public string signature = null;

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                RequestUtility.SetHttpProxy("192.168.72.237", "8080", "jinyunni", "xxxx");

                JsApiTicketContainer.Register(CorpID, Secret);
                timestamp = JSSDKHelper.GetTimestamp();
                nonceStr = JSSDKHelper.GetNoncestr();
                jsapi_ticket = JsApiTicketContainer.GetTicket(CorpID, Secret, true);
                signature = JSSDKHelper.GetSignature(jsapi_ticket, nonceStr, timestamp, url);
            }
        }
    }
}

下面是HTML代码

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="wxwork.Index" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>

    <div>
        <button id="sys" style="height: 100px; width: 400px;">扫一扫</button>
    </div>

    <script>
        wx.config({
            debug: false,
            beta: true,
            appId: '<%=CorpID%>',
            timestamp: <%=timestamp%>,
            nonceStr: '<%=nonceStr%>',
                signature: '<%=signature%>',
                jsApiList: [
                    'checkJsApi',
                    'onMenuShareAppMessage',
                    'onMenuShareWechat',
                    'shareAppMessage',
                    'shareWechatMessage',
                    'startRecord',
                    'stopRecord',
                    'onVoiceRecordEnd',
                    'playVoice',
                    'pauseVoice',
                    'stopVoice',
                    'uploadVoice',
                    'downloadVoice',
                    'chooseImage',
                    'previewImage',
                    'uploadImage',
                    'downloadImage',
                    'getNetworkType',
                    'openLocation',
                    'getLocation',
                    'hideOptionMenu',
                    'showOptionMenu',
                    'hideMenuItems',
                    'showMenuItems',
                    'hideAllNonBaseMenuItem',
                    'showAllNonBaseMenuItem',
                    'closeWindow',
                    'scanQRCode',
                    'previewFile',
                    'openEnterpriseChat',
                    'selectEnterpriseContact',
                    'onHistoryBack',
                    'openDefaultBrowser',
                ]
        });


        wx.ready(function () {

            $(function () {
                $("#sys").click(function () {
                    wx.scanQRCode({
                        desc: 'scanQRCode desc',
                        needResult: 1, // 默认为0,扫描结果由企业微信处理,1则直接返回扫描结果,
                        scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码,默认二者都有
                        success: function (res) {
                            // 回调
                            alert(res.resultStr);
                        },
                        error: function (res) {
                            if (res.errMsg.indexOf('function_not_exist') > 0) {
                                alert('版本过低请升级')
                            }
                        }
                    });
                });



            }


            );





        });

    </script>



</body>
</html>

猜你喜欢

转载自blog.csdn.net/a22698488/article/details/79143074