zoukankan      html  css  js  c++  java
  • 通过数据流处理-微信小程序生成临时二维码

    1.小程序请求代码

    onLoad: function (options) {
        var that = this
        api.Login(function (login) {
          var codeModel = new function () { }
          codeModel.scene = login.UserId
          codeModel.width=430
          codeModel.auto_color = false
          codeModel.line_color = { "r": "0", "g": "0", "b": "0" }
          console.log('----')
     
          api.RequestApiURL("WeixinAPI/CreateMyCode", { data: JSON.stringify(codeModel)}, function (e) {
            console.log(e)
            wx.hideLoading()
            console.log(e.data.data)
            that.setData({
              imgurl: e.data.data
            })
          })
        })
      }

    2.后台代码(代理请求获取二维码的数据流)

    public string CreateMyCode(string data)
           {
               string gettokenurl = string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", "appid", "AppSecret");
               string access_token = GetWebRequest(gettokenurl);
               if (access_token.IndexOf("access_token") > 0)
               {
                   access_token = access_token.Substring(access_token.IndexOf(":") + 2,
                       access_token.IndexOf(",") - access_token.IndexOf(":") - 3);
               }
               string url = string.Format("http://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token={0}", access_token);
               var io = PostMoths(url, data);
               byte[] by = StreamToBytes(io);
     
               var rs = new ReturnResult<byte[]>(by);
               return rs.Serialize();
           }

    3.二维码显示

     <view class="weui-media-box__hd_in-appmsg">
              <image class="weui-media-box__thumb" src="data:image/jpeg;base64,{{imgurl}}" />
    </view>
  • 相关阅读:
    The password has to have a minimum of 6 characters, including at least 1 small letter, 1 uppercase letter and 1 number
    Angular i18n的技术分享、踩过的坑
    转: .Net 4.0 ExpandoObject 使用
    min_square
    KALMAN PYTHON
    双系统安装 win + ubuntu
    docker
    drl
    shell
    导航定位方案
  • 原文地址:https://www.cnblogs.com/cosyer/p/8489300.html
Copyright © 2011-2022 走看看