微信OAuth2网页授权

时间:2015-01-27 14:44:01   收藏:0   阅读:347
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;
        }
    }
}

 

原文:http://www.cnblogs.com/slu182/p/4252732.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!