<%@ 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
})
}
})