通过数据流处理-微信小程序生成临时二维码

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>

 

通过数据流处理-微信小程序生成临时二维码

上一篇:人工智能八大行业创新应用,开启智慧之路


下一篇:微信小程序 --- app.json文件