微信服务号 接口调用
来源:互联网 发布:网络时时彩案件判刑 编辑:程序博客网 时间:2024/06/05 08:41
public ActionResult Index() { //ViewBag.openid = "oCaDVv1j2bt_RjbiS1aHtfV9sn6E"; string appid = DAL.CommWeb.Appid; string secret = DAL.CommWeb.Secret; ViewBag.appid = appid; ViewBag.secret = secret; #region 获取token string url_access_token = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret; string obj_token = DAL.CommWeb.RequestUrl(url_access_token); dynamic dy_token = DAL.JsonParser.FromJson(obj_token); string access_token = dy_token.access_token; #endregion }
using System;using System.Collections.Generic;using System.Configuration;using System.IO;using System.Linq;using System.Net;using System.Text;namespace Mobile_Healthy.DAL{ public class CommWeb { public CommWeb() { } static public string Appid { get { string _appid = ConfigurationManager.AppSettings["appid"]; return _appid; } } static public string Secret { get { string _secret = ConfigurationManager.AppSettings["secret"]; return _secret; } } static public string RequestUrl(string url) { //{\"access_token\":\"zeOij5UaHVlkFKOj89SGgpTL2tgUFH_gFUA_oYohsPSkhWiWcjU1WaL_S-N-68O8TB9ryIf5PVeOWuggyW7g51vzH1beukT7Mv1W1KLxL-b3SilkR9cZuZ2leCvAYjdNJTKjADAPZQ\",\"expires_in\":7200} try { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); //创建一个请求示例 HttpWebResponse response = (HttpWebResponse)request.GetResponse(); //获取响应,即发送请求 Stream responseStream = response.GetResponseStream(); StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8); string html = streamReader.ReadToEnd(); if (response != null) response.Close(); return html; } catch (Exception ex) { return ex.ToString(); } } }}
using System;using System.Collections;using System.Collections.Generic;using System.Collections.ObjectModel;using System.Dynamic;using System.Linq;using System.Web;using System.Web.Script.Serialization;namespace Mobile_Healthy.DAL{ public class JsonParser { /// <summary> /// 从json字符串到对象。 /// </summary> /// <param name="jsonStr"></param> /// <returns></returns> static public dynamic FromJson(string jsonStr) { JavaScriptSerializer jss = new JavaScriptSerializer(); jss.RegisterConverters(new JavaScriptConverter[] { new DynamicJsonConverter() }); dynamic glossaryEntry = jss.Deserialize(jsonStr, typeof(object)) as dynamic; return glossaryEntry; } } public class DynamicJsonConverter : JavaScriptConverter { public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer) { if (dictionary == null) throw new ArgumentNullException("dictionary"); if (type == typeof(object)) { return new DynamicJsonObject(dictionary); } return null; } public override IDictionary<string, object> Serialize(object obj, JavaScriptSerializer serializer) { throw new NotImplementedException(); } public override IEnumerable<Type> SupportedTypes { get { return new ReadOnlyCollection<Type>(new List<Type>(new Type[] { typeof(object) })); } } } public class DynamicJsonObject : DynamicObject { private IDictionary<string, object> Dictionary { get; set; } public DynamicJsonObject(IDictionary<string, object> dictionary) { this.Dictionary = dictionary; } public override bool TryGetMember(GetMemberBinder binder, out object result) { result = this.Dictionary[binder.Name]; if (result is IDictionary<string, object>) { result = new DynamicJsonObject(result as IDictionary<string, object>); } else if (result is ArrayList && (result as ArrayList) is IDictionary<string, object>) { result = new List<DynamicJsonObject>((result as ArrayList).ToArray().Select(x => new DynamicJsonObject(x as IDictionary<string, object>))); } else if (result is ArrayList) { result = new List<object>((result as ArrayList).ToArray()); } return this.Dictionary.ContainsKey(binder.Name); } }}
0 0
- 微信服务号 接口调用
- 微信接口调用
- 微信接口调用
- 微信服务号相关接口开发
- 深入浅出微信公众平台实战开发(微网站、LBS云、Api接口调用、服务号高级接口)
- 微信公众平台开发视频教程(微网站、LBS云、Api接口调用、服务号高级接口)
- 微信公众号 调用红包接口
- 微信js接口调用
- 微信调用APP接口
- 调用微信接口方法
- 微信公众平台开发详解——由浅入深(微网站、LBS云、Api接口调用、服务号高级接口)
- 微信公众平台服务号API开发接口
- 微信公众平台"服务号"接口验证 PHP版
- java调用微信企业号各种接口实例
- 微信公众号调用客服接口发送信息
- 微信公众号调用上传永久素材接口
- 微信企业号开发之access_token接口调用示例
- 微信公众号接口调用配置常见误区
- 传输协议
- MyEclipse常用插件使用教程
- ScrollView中嵌入Listview,当item高度不一样的时候,item展示不全问题
- 算法链表合并
- 邻接表用数组模拟+dij+优先队列,dfs剪枝+邻接表用数组模拟,链表+dij+优先队列
- 微信服务号 接口调用
- 解决ScrollView 与 ListView 的滑动冲突
- 搜索框即时搜索的实现
- 内联函数小结
- 在多选情况下,动态获取动态的select的option的text值
- ubuntu/Linux 下 Pycharm 安装中文汉化包
- delphi 得到执行程序的当前所在完整路径
- android图片滚动选择器的实现
- git添加忽略文件无效