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 ...
随机推荐
- 1-Spark-1-性能调优-数据倾斜1-特征/常见原因/后果/常见调优方案
数据倾斜特征:个别Task处理大部分数据 后果:1.OOM;2.速度变慢,甚至变得慢的不可接受 常见原因: 数据倾斜的定位: 1.WebUI(查看Task运行的数据量的大小). 2.Log,查看log ...
- springboot使用过滤器Filter
先创建过滤器配置类: ## 引入的包部分省略... @Configuration public class FilterConfig { @SuppressWarnings({"rawtyp ...
- go工程组织规范
go编码以workspace形式管理,一个workspace包含所有的Go编码,包含多个版本控制仓库(例如使用git管理的多个仓库).每个仓库包含多个包package,每个package是一个单独的路 ...
- 分配swap分区空间
1. 分区,并修改为swap分区ID [root@centos2 ~]# fdisk /dev/sdb 欢迎使用 fdisk (util-linux ). 更改将停留在内存中,直到您决定将更改写入磁盘 ...
- JavaSE字符串日期与时间拼接小列子与JSON小列子
1.在对象中有个字段为Timestamp类型,需要将数据库的开始日期字段和开始时间字段拼接成一个字段开始字段 private static Timestamp getDateTime(String d ...
- word标题和序号列表的使用
- react navtagion 头部有返回按钮 标题不居中解决方法
头部右边写一个隐藏的组件 hederRight:( <View><View> )
- BOM常用属性与方法
BOMBrowser Object Modelwindow浏览器窗口window方法locationlocation常用属性screen显示器屏幕screen常用属性navigator浏览器软件nav ...
- LGOJP4381 [IOI2008]Island
题目链接 https://www.luogu.org/problem/P4381 题解 基环树直径的板子.但是dfs会爆栈...所以最后改成了bfs.还是一个很考验码力的板子. 首先基环树的直径显然有 ...
- 生成一个uuid字符串,并去除多余的符号
for(int i=0;i<10;i++){ String uuid = UUID.randomUUID().toString().replaceAll("-", " ...