using System; using System.Collections.Generic; using System.Linq; using System.Text; using YTO.WeiXin.Model; using YTO.Framework.Core; using Newtonsoft.Json.Linq; using Newtonsoft.Json; namespace WeiXin.Core { public class OAuth20 { public static string OAuth(string code) { string AppID = JobBase.GetConfParamValue(ParamEnum.AppID).ToString(); string AppSecret = JobBase.GetConfParamValue(ParamEnum.AppSecret).ToString(); string url = string.Format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code", AppID, AppSecret, code); string Jsonstr = RequestHelper.SendGet(url); JObject obj = JObject.Parse(Jsonstr); string openId = obj["openid"].ToString().Replace("\"",string.Empty); return openId; } } }