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 ...
随机推荐
- CRM-Modelformset
CRM-Modelformset 效果图 利用modelformset实现上面的效果: views.py文件: from user.formself.myform import RegForm, Cu ...
- Django——Xadmin中的功能
app_label 功能 如果不在标准models.py里面定义model,则必须指定这个model归属于哪个app. 使用 app_label = 'oms' actions 功能 Action插件 ...
- 191011 python3-format函数
# 题目:一球从100米高度自由落下,每次落地后反跳回原高度的一半:# 再落下,求它在第10次落地时,共经过多少米?第10次反弹多高?方法一: l = 100.0 s = 100 for i in r ...
- Windows通过SSH远程登录Linux主机
准备工作:1.Windows系统下装有VMware虚拟机且是Linux系统2.终端连接工具Xshell 63.本次实验系统IP如下 系统 IP Windows10 192.168.37.111 Cen ...
- C++Primer第五版 练习8.6答案详解
重写7.1.1节书店程序(第299页),从文件中读取一个交易记录.将文件名作为一个参数传递给main. 本题所需源文件如下: Sales_data.h文件: #pragma once #include ...
- Codes: MODERN ROBOTICS Ch.4_基于PoE的正运动学代码实现
%%1 基于PoE space form 的正运动学求解 % 输入M矩阵.螺旋轴列表Slist(column vector).关节角向量qlist(column vector),输出齐次变换矩阵T f ...
- 评估预测函数(1)---算法不能达到我们的目的时,Deciding what to try next
在设计机器学习系统时,一些建议与指导,让我们能明白怎么选择一条最合适,最正确的道路. 当我们要开发或者要改进一个机器学习系统时,我们应该接下来做些什么? try smaller sets of fea ...
- spring boot学习笔记(一)
(翻译看个人意愿) 官方介绍: Spring Boot makes it easy to create stand-alone, production-grade Spring based Appli ...
- notepad++ 调整行间距
在“设置”-“语言格式设置”里面,找到style里面的Line number margin一项,调整字体大小就可以调整左边标号的大小,然后文本内容的行间距即可任意调整.
- Chocolatey——windows下的包管理器
前言 windows 包管理器 | https://chocolatey.org/ 命令 文档 | https://chocolatey.org/docs 根据使用会补充命令