1.微信小程序的必备Model

 public class WxConfig
{
/// <summary>
/// 小程序的appId
/// 登录小程序可以直接看到
/// </summary>
public string AppId { get; set; }
/// <summary>
/// 小程序的AppSecret
/// 只能修改,不能查看
/// </summary>
public string AppSecret { get; set; }
/// <summary>
/// 商户key:微信商户平台(pay.weixin.qq.com)-->账户设置-->API安全-->密钥设置(这个key是自己定义的。32位数字加字母组成的)
/// </summary>
public string PayKey { get; set; }
/// <summary>
/// 商户号
/// 支付时需要
/// </summary>
public string MchId { get; set; } /// <summary>
/// 微信的token 用过的都知道是干嘛的
/// </summary>
public string Access_token { get; set; } /// <summary>
/// 最新获取token的时间.token的时效只有7200秒
/// </summary>
public DateTime UpTokenTime { get; set; }
}

2.后台Get请求方法和POST请求方法

 /// <summary>
/// GET请求方式
/// </summary>
/// <param name="postUrl"></param>
/// <returns></returns>
public static string GetWebRequest(string postUrl)
{
var ret = string.Empty;
try
{
var request = WebRequest.Create(postUrl);
var response = request.GetResponse();
var reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8"));
ret = reader.ReadToEnd();
reader.Close();
reader.Dispose();
response.Close();
}
catch (Exception ex)
{
return ex.Message;
}
return ret;
} /// <summary>
/// Post获取数据流
/// </summary>
/// <param name="url"></param>
/// <param name="data"></param>
/// <returns></returns>
public static Stream PostMoths(string url, string data)
{
HttpWebRequest request;
request = (System.Net.HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
//string paraUrlCoded = param;
byte[] payload;
//payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
payload = System.Text.Encoding.UTF8.GetBytes(data);
request.ContentLength = payload.Length;
Stream writer = request.GetRequestStream();
writer.Write(payload, , payload.Length);
writer.Close();
System.Net.HttpWebResponse response;
response = (System.Net.HttpWebResponse)request.GetResponse();
//System.IO.Stream s;
return response.GetResponseStream();
}

3.备注:小程序有些api的接口都只能在后台进行请求。不要在前台进行请求.合理利用:app.js的globalData对象

.NET开发微信小程序(基础配置)的更多相关文章

  1. vsCode 开发微信小程序插件

    用 vsCode 开发微信小程序可以配置以下插件,让开发更美好: 1. vscode weapp api 2. vscode wxml 3. vscode-wechat 4. Easy WXLESS ...

  2. 关于开发微信小程序后端linux使用xampp配置https

    关于开发微信小程序后端linux使用xampp配置https 背景 由于最近开发微信小程序,前后端交互需要使用https协议,故需要配置https服务 服务器环境 服务器系统 ubuntu 环境 xa ...

  3. 使用wepy开发微信小程序商城第二篇:路由配置和页面结构

    使用wepy开发微信小程序商城 第二篇:路由配置和页面结构 前言: 最近公司在做一个微信小程序的项目,用的是类似于vue的wepy框架.我也借此机会学习和实践一下. 小程序官方文档:https://d ...

  4. 微信小程序基础入门

    准备 Demo 项目地址 https://github.com/zce/weapp-demo Clone or Download(需准备GIT环境) $ cd path/to/project/root ...

  5. 用Vue.js开发微信小程序:开源框架mpvue解析

    前言 mpvue 是一款使用 Vue.js 开发微信小程序的前端框架.使用此框架,开发者将得到完整的 Vue.js 开发体验,同时为 H5 和小程序提供了代码复用的能力.如果想将 H5 项目改造为小程 ...

  6. 微信小程序基础

    前言 什么是微信小程序,它是一种轻量级的APP,它与常规App来说,无需下载安装即可使用,它嵌于微信App中,要使用微信小程序你只需要搜索一下微信小程序的名称就好,如近期的"Google的画 ...

  7. 利用WordPress REST API 开发微信小程序从入门到放弃

    自从我发布并开源WordPress版微信小程序以来,很多WordPress网站的站长问有关程序开发的问题,其实在文章:<用微信小程序连接WordPress网站>讲述过一些基本的要点,不过仍 ...

  8. 使用uView UI+UniApp开发微信小程序

    在前面随笔的介绍中,我们已经为各种框架,已经准备了Web API.Winform端.Bootstrap-Vue的公司动态网站前端.Vue&Element的管理前端等内容,基本都是基于Web A ...

  9. 开发微信小程序中SSL协议的申请、证书绑定、TLS 版本处理等

    在上篇随笔<基于微信小程序的系统开发准备工作>介绍了开发微信小程序的一些前期的架构设计.技术路线 .工具准备等方面内容,本篇随笔继续这个步骤,逐步介绍我们实际开发过程中对SSL协议的申请及 ...

  10. wn-cli 像React组件开发一样来开发微信小程序

    项目地址:wn-cli wn-cli wn-cli 像React组件开发一样来开发微信小程序 名字由来:wn -> weapp native 取第一个字母 Install npm install ...

随机推荐

  1. Java进阶(二十三)java中long类型转换为int类型

    java中long类型转换为int类型 由int类型转换为long类型是向上转换,可以直接进行隐式转换,但由long类型转换为int类型是向下转换,可能会出现数据溢出情况: 主要以下几种转换方法,供参 ...

  2. ubuntu virtualbox xp无声音解决

    太简单了,记录一下解决方法,进入xp,打开设备管理器,对着ac97设备驱动 点右键,点更新驱动,更新一下就ok了. 这时候去控制面板,就可以看到有音频设备了. 具体步骤如下: 第一步,virtualb ...

  3. 证书,CSP与Openssl

    证书,CSP与Openssl 起因 最近在研究更安全的交互体系,自然想到的就是提供证书的交互方式.给用户分配一对公私钥,然后将私钥交给用户保管,用户在登录或者一些关键操作的时候通过私钥签名,从而保证其 ...

  4. 打造你的开发神器——介绍Android Studio上的几个插件

    这个月因为各种事情在忙,包括赶项目,回老家,还有准备旅游的事,所以应该写不了四篇博客了.今天介绍一下关于Android Studio 的几个好用的插件,都是我在用的,它们或能帮你节省时间,或者让你心情 ...

  5. 【cocos 2d-x】VS2012+win7+cocos2d-x3.0beta2开发环境配置

    本系列文章由@二货梦想家张程 所写,转载请注明出处. 作者:ZeeCoder  微博链接:http://weibo.com/zc463717263 我的邮箱:michealfloyd@126.com ...

  6. cocos2d-x项目与vs2013编译

    cocos2d-x项目与vs2013编译 2014-12-17 cheungmine 因为C++11引入了众多开源软件的特性,导致cocos2d-x r3.3项目无法用 vs2010编译. 所以安装了 ...

  7. android查看源码的时候看不了

    原因:未关联android中jar包源码 解决方案:导入sdk---->>resource---->>api 这样就可以在代码中查看源码了.

  8. 嵌入式C开发---用循环实现左移右移

    //将n左移m位 int byte_to_left_move(int n , int m) { int i , ret = 1 ; if(n == 0 || n < 0) { return ; ...

  9. mybatis源码之BaseStatementHandler

    /** * @author Clinton Begin */ public abstract class BaseStatementHandler implements StatementHandle ...

  10. LeetCode(28)-Remove Duplicates from Sorted Array

    题目: Given a sorted array, remove the duplicates in place such that each element appear only once and ...