Foxtable(狐表)用户栏目专家坐堂 → 在网页实现扫码输入数据中,代码还没读透,想请教下怎么做,才能只返回扫描的条码内容,不需要条码的编码格式


  共有2607人关注过本帖树形打印复制链接

主题:在网页实现扫码输入数据中,代码还没读透,想请教下怎么做,才能只返回扫描的条码内容,不需要条码的编码格式

帅哥哟,离线,有人找我吗?
xa139
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:282 积分:2835 威望:0 精华:0 注册:2019/4/23 11:17:00
在网页实现扫码输入数据中,代码还没读透,想请教下怎么做,才能只返回扫描的条码内容,不需要条码的编码格式  发帖心情 Post By:2020/10/8 11:37:00 [只看该作者]

 

设计步骤

1、在微信管理后台设置可信域名,只能在该域名下调用JS-SDK,域名必须经过备案。

2、新增一个自定义函数,函数名为"GetJsSignature",用于生成JS-SDK的授权签名,代码为:

Static
CreateTime As Date '记录最近一次生成Ticket 的时间
Static
Ticket As String '记录最近一次生成的Ticket
Dim
tp As TimeSpan = Date.Now - CreateTime
Dim
ul As String = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token={0}"
If
tp.TotalSeconds > 3600 Then
    Dim hc As New HttpClient(CExp(ul,Functions.Execute("GetQYAccessToken")))
    Dim ret As String = hc.GetData()
    If ret = "" Then
'
如果失败,再尝试一次
        hc.GetData()
    End If
    CreateTime = Date.Now()
    Dim jo As JObject = JObject.Parse(ret)
    If jo("errcode") = "0" Then
        Ticket = jo("ticket")
    Else
        MessageBox.show(
"
获取jsapi_ticket,原因:" & vbcrlf & jo.ToString)
    End
If

End
If
Dim
signature As String = CExp("jsapi_ticket={0}&noncestr={1}&timestamp={2}&url={3}",Ticket,args(0),args(1),args(2))
Return
Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(signature, "SHA1").ToLower()

2、在d:\web\lib目录下新建一个文本文件jssdk.js,内容为:

wx.ready(function () {
    document.getElementById('
scan').onclick = function () {
        wx.scanQRCode({
            needResult: 1,
            scanType: ['qrCode','barCode'],
            success: function (res) {
                document.getElementById('
number
').value = res.resultStr;
            }
        });
    };
});
wx.error(function (res) {
    //alert(res.errMsg);
});

实际开发的时候,你要变化的只有红色的两处,scan为网页中扫码输入按钮的id,number为网页中产品编号输入框的id。

3、最后将HttpRequest事件代码设置为:

Select
Case e.Path
    Case "test.htm",""
        Dim wb As New weui
        wb.AppendHTML("<script src='http://res.wx.qq.com/open/js/jweixin-1.0.0.js'></script>",True)
'
引入JS-SDK
        wb.AppendHTML("<script src='./lib/jssdk.js'></script>")
'
引入脚本文件
       
'
在页面注入权限验证配置
        Dim st As New Date(1970,1,1,8,0,0)
        Dim appid As String = "wxa31aba4cd83af57e"
'CorpID
        Dim timestamp As Integer = CInt((Date.Now - st).TotalSeconds())
'
时间戳
        Dim noncestr As String = Rand.NextString(16)
'
随机字符
        Dim url As String  = e.Request.URL.ToString
'
当前页面地址
        Dim signature As String = Functions.Execute("GetJsSignature", noncestr, timestamp, url)
'
生成权限验证签名
        Dim cfg As String = "wx.config({appId:'{0}',timestamp:{1},nonceStr:'{2}',signature:'{3}',jsApiList:['scanQRCode']});"
        wb.AppendHTML("<script>" & CExp(cfg,appid,timestamp,noncestr,signature) & "</script>",True)
       
'开始正常生成网页内容
       
wb.AddForm("","form1","test.htm")
        With wb.AddInputGroup("form1","ipg1",
"
产品输入")
            .AddInput("product",
"
产品","text")
            With .AddInputCell("ic1")
                .AddLabel("lbh",
"
编号",0)
                .AddInput("number","text",1)
                .AddVcodeButton("scan",
"
扫码输入",2) '增加二维码扫描按钮,2表示显示在右边
            End With
        End With
        With wb.AddButtonGroup("form1","btg1",True)
            .Add("btn1",
"
确定", "submit")
        End With
       
e.WriteString(wb.Build) '生成网页
End
Select


 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107739 积分:548028 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/10/8 11:43:00 [只看该作者]

不需要条码的编码格式是什么意思?请举例说明

 回到顶部
帅哥哟,离线,有人找我吗?
shyilin4
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:37 积分:412 威望:0 精华:0 注册:2018/10/16 17:43:00
  发帖心情 Post By:2020/10/8 11:48:00 [只看该作者]

 var code = res.resultStr;  
 if (code.indexOf(",") >= 0) {
                    code = code.split(",")[1];
                }
他可能要这个

 回到顶部
帅哥哟,离线,有人找我吗?
xa139
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:282 积分:2835 威望:0 精华:0 注册:2019/4/23 11:17:00
回复:(shyilin4) var code = res.resultStr; ...  发帖心情 Post By:2020/10/8 12:25:00 [只看该作者]

多谢,就是这个意思,还想请教
wx.ready(function () {
    document.getElementById('scan').onclick = function () {
        wx.scanQRCode({
            needResult: 1,
           scanType: ['qrCode','barCode'],
            success: function (res) {
                document.getElementById('number').value =res.resultStr;
            }
        });
    };
});
wx.error(function (res) {
    //alert(res.errMsg);
});
不懂 js 如何行文,请教怎么插入到这段里面

 回到顶部
帅哥哟,离线,有人找我吗?
xa139
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:282 积分:2835 威望:0 精华:0 注册:2019/4/23 11:17:00
这样可以吗  发帖心情 Post By:2020/10/8 12:27:00 [只看该作者]

wx.ready(function () {
    document.getElementById('scan').onclick = function () {
        wx.scanQRCode({
            needResult: 1,
           scanType: ['qrCode','barCode'],
            success: function (res) {
                document.getElementById('number').value = res.resultStr;
                document.getElementById('number').value= document.getElementById('number').value.split(",")[1]
            }
        });
    };
});
wx.error(function (res) {
    //alert(res.errMsg);
});

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107739 积分:548028 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/10/8 13:47:00 [只看该作者]

wx.ready(function () {
    document.getElementById('scan').onclick = function () {
        wx.scanQRCode({
            needResult: 1,
           scanType: ['qrCode','barCode'],
            success: function (res) {
var code = res.resultStr;  
 if (code.indexOf(",") >= 0) {
                    code = code.split(",")[1];
                }
                document.getElementById('number').value =code ;
            }
        });
    };
});

 回到顶部
帅哥哟,离线,有人找我吗?
evolymft
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1028 积分:7191 威望:0 精华:0 注册:2016/6/16 15:23:00
  发帖心情 Post By:2021/10/4 10:46:00 [只看该作者]

学习学习学习

 回到顶部