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

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>
上一篇:iOS中 KVO 键值观察者


下一篇:Netty浅析