1. 程式人生 > >微信小程序獲取請求數據

微信小程序獲取請求數據

pub back close settime content reference lin plain 沒有

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

微信小程序獲取請求數據