微信小程序获取请求数据
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <%@ WebHandler Language= "C#" Class= "CodeTest" %> using System; using System.Web; using LitJson; public class CodeTest : IHttpHandler { public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/plain" ; //获取webservice的数据 WebReference.Service1 wx = new WebReference.Service1(); string code = context.Request.Params[ "codes" ]; WebReference.ProductInfo sd = wx.GetProductInfo(code); JsonData data = new JsonData(); data[ "product_name" ] = sd.Product_Name; data[ "product_spec" ] = sd.Product_Spec; context.Response.Write(data.ToJson()); } public bool IsReusable { get { return false ; } } } |
//index.js //获取应用实例 const app = getApp() Page({ data: { motto: 'Hello World', flag: 'false', userInfo: {}, showView: true, animation: '', hasUserInfo: false, canIUse: wx.canIUse('button.open-type.getUserInfo'), name:'', spec:'' }, ClickHongbao: function () { var animation = wx.createAnimation({ duration: 1000, delay: 0, transformOrigin: "50% 50%", timingFunction: "linear" }) this.animation = animation animation.translate(50, 0).step() this.setData({ animationData: animation.export() }) setTimeout(function () { animation.translate(0, 0).step() this.setData({ animationData: animation.export() }) var that = this; that.setData({ showView: (!that.data.showView) }), this.setData({ flag: (!that.data.flag) }) }.bind(this), 100) }, closes: function () { var that = this; this.setData({ flag: (!that.data.flag) }), that.setData({ showView: (!that.data.showView) }) }, //事件处理函数 bindViewTap: function() { wx.navigateTo({ url: '../logs/logs' }) }, onLoad: function () { var that=this if (app.globalData.userInfo) { this.setData({ userInfo: app.globalData.userInfo, hasUserInfo: true }) } else if (this.data.canIUse){ // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 // 所以此处加入 callback 以防止这种情况 app.userInfoReadyCallback = res => { this.setData({ userInfo: res.userInfo, hasUserInfo: true }) } } else { // 在没有 open-type=getUserInfo 版本的兼容处理 wx.getUserInfo({ success: res => { app.globalData.userInfo = res.userInfo this.setData({ userInfo: res.userInfo, hasUserInfo: true }) } }) } wx.request({ url: 'https://t.risingtec.cn/CodeTest.ashx', data:{ codes:'9410887704315070' }, header:{ "Content-Type": "application/x-www-form-urlencoded" }, method:"POST", success:function(res){ console.log(res); that.setData({ name:res.data.product_name, spec: res.data.product_spec }) } }) }, getUserInfo: function(e) { console.log(e) app.globalData.userInfo = e.detail.userInfo this.setData({ userInfo: e.detail.userInfo, hasUserInfo: true }) } })
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!