ASP.NET_微信JS_SDK调用
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Threading.Tasks;
namespace wechat_test
{
/// <summary>
/// test 的摘要说明
/// </summary>
public class test : IHttpHandler
{
public class tokenObj
{
public string access_token { get; set; }
public string expires_in { get; set; }
}
public class jsapiTicketObj
{
public string errcode { get; set; }
public string errmsg { get; set; }
public string ticket { get; set; }
public string expires_in { get; set; }
}
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string grant_type = "client_credential";//获取access_token填写client_credential
string AppId = "wx07b6790c0b49731a";//第三方用户唯一凭证
string secret = "8fe8a582e16436e89256f74b2b7c5275";//第三方用户唯一凭证密钥,即appsecret
//这个url链接地址和参数皆不能变
string url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=" + grant_type + "&appid=" + AppId + "&secret=" + secret;
//string json = JsonConvert.SerializeObject(RequestUrl(url));
tokenObj t_o = JsonConvert.DeserializeObject<tokenObj>(RequestUrl(url));
//string ticket = "";
string access_token = t_o.access_token;
string url2 = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + access_token + "&type=jsapi";//这个url链接和参数不能变
jsapiTicketObj j_t_o = JsonConvert.DeserializeObject<jsapiTicketObj>(RequestUrl(url2));
context.Response.Write(j_t_o.ticket);
}
#region 请求Url,不发送数据
/// <summary>
/// 请求Url,不发送数据
/// </summary>
public static string RequestUrl(string url)
{
return RequestUrl(url, "GET");
}
#endregion
#region 请求Url,不发送数据
/// <summary>
/// 请求Url,不发送数据
/// </summary>
public static string RequestUrl(string url, string method)
{
// 设置参数
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
CookieContainer cookieContainer = new CookieContainer();
request.CookieContainer = cookieContainer;
request.AllowAutoRedirect = true;
request.Method = method;
request.ContentType = "text/html";
request.Headers.Add("charset", "utf-8");
//发送请求并获取相应回应数据
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
//直到request.GetResponse()程序才开始向目标网页发送Post请求
Stream responseStream = response.GetResponseStream();
StreamReader sr = new StreamReader(responseStream, Encoding.UTF8);
//返回结果网页(html)代码
string content = sr.ReadToEnd();
return content;
}
#endregion
public bool IsReusable
{
get
{
return false;
}
}
}
}
ASP.NET_微信JS_SDK调用的更多相关文章
- ASP.NET微信公众号用于给指定OpenId用户发送红包
ASP.NET微信公众号用于给指定OpenId用户发送红包 微信公众号要实现对指定用户发送红包,必须指定一个存放兵发放金额的商户号,在微信商户平台里面申请商户号并获取相关参数例如发送红包所要用到的安全 ...
- ASP.net 中手工调用WS(POST方式)
ASP.net 中手工调用WS(POST方式)核心代码:string strUrl="http://localhost:21695/service1.asmx/getmythmod" ...
- 由ASP.NET所谓前台调用后台、后台调用前台想到HTTP——实践篇(二)
在由ASP.NET所谓前台调用后台.后台调用前台想到HTTP——理论篇中描述了一下ASP.NET新手的三个问题及相关的HTTP协议内容,在由ASP.NET所谓前台调用后台.后台调用前台想到HTTP—— ...
- 微信分享调用 -- c#篇
微信分享调用JS -- c#篇 1.前端 1.1 导入微信端的JS 如果你的网址是http,则地址为 http://res.wx.qq.com/open/js/jweixin-1.0.0.js ...
- asp.net 微信支付 错误解决方案
asp.net 微信支付 错误解决方案 在网上看到有人解决方案为: 解决方法 出现这种错误网上查出现有的原因是: 订阅号没有相关的权限 账号没有认证,没有相关的权限 那么这里遇到问题两种都不是.开发账 ...
- 控制ASP.NET Web API 调用频率与限流
ASP.NET MVC 实现 https://github.com/stefanprodan/MvcThrottle ASP.NET WEBAPI 实现 https://github.com/stef ...
- 由ASP.NET所谓前台调用后台、后台调用前台想到HTTP
由ASP.NET所谓前台调用后台.后台调用前台想到HTTP 在由ASP.NET所谓前台调用后台.后台调用前台想到HTTP——理论篇中描述了一下ASP.NET新手的三个问题及相关的HTTP协议内容,在由 ...
- ASP.NET所谓前台调用后台、后台调用前台想到HTTP——实践篇
由ASP.NET所谓前台调用后台.后台调用前台想到HTTP——实践篇 在由ASP.NET所谓前台调用后台.后台调用前台想到HTTP——理论篇中描述了一下ASP.NET新手的三个问题及相关的HTTP协议 ...
- asp.net中怎样调用存储过程和存储过程的写法(转载,留着自己看)
asp.net中怎样调用存储过程和存储过程的写法 创建一个只有输入参数的存储过程 create procedure proc_user@name varchar(20),@Password varch ...
随机推荐
- java web编程 servlet
先从请求的信息里面获取协议,版本协议如果是1.1结尾的就报错,也就是我们常见的405报错: 405是协议请求方式错误,所以要重写doget或者dopost方法,直接调用父类的get和post方法是会报 ...
- MySQL Backup--Xtrabackup备份限速问题
在innobackupex 2.4版本中,有两个参数用来限制备份速度: --throttle=# This option specifies a number of I/O operations (p ...
- Spark 用Scala和Java分别实现wordcount
Scala import org.apache.spark.{SparkConf, SparkContext} object wordcount { def main(args: Array[Stri ...
- 随Linux开机自动启动mysql
在MySQL的管理过程中,会遇到PC Server脱机或者重启,我需要在主机启动后再将MySQL服务启动.如果上百台或者更多的MySQL主机进行维护时,可能会有多台主机出现类似问题,要是每次都手动操作 ...
- Random Forest(sklearn参数详解)
2016年08月17日 10:32:42 铭霏 阅读数:36874 版权声明:本文为博主原创文章,博主转载请附加原文链接并声明. https://blog.csdn.net/u012102306/ ...
- js中绑定事件处理函数,使用event以及传递额外数据
IE8中使用attachEvent绑定事件处理函数时,不能直接向event 对象添加数据属性.可以用属性复制的方法,包装新的event对象. 1. 属性复制var ObjectExtend = fun ...
- 51nod 1720 祖玛
吉诺斯在手机上玩祖玛的游戏.在这个游戏中,刚开始有n个石头排成一排,第i个石头的颜色是ci.游戏的目标是尽可能快的把所有石头都消掉. 每一秒钟,吉诺斯可以选择一段连续的子段,并且这个子段是回文,然后把 ...
- 《逆袭团队》第七次作业:团队项目设计完善&编码
实验十一 团队作业7:团队项目设计完善&编码 内容 项目 软件工程 任课教师博客主页链接 作业链接地址 团队作业7:团队项目设计完善&编码 团队名称 逆袭团队 具体目标 (1)完善团队 ...
- CTSC2010 珠宝商
珠宝商 题目描述 Louis.PS 是一名精明的珠宝商,他出售的项链构造独特,很大程度上是因为他的制作方法与众不同.每次 Louis.PS 到达某个国家后,他会选择一条路径去遍历该国的城市.在到达一个 ...
- 【Python学习】Python3 基本数据类型
参考学习地址:https://www.runoob.com/python3/python3-data-type.html Python3 基本数据类型 Python 中的变量不需要声明.每个变量在使用 ...