Ejemplo n.º 1
0
        public override string GetRawUserInfo()
        {
            var accessToken = GetAccessToken();

            if (accessToken == null || accessToken.alipay_system_oauth_token_response == null)
            {
                throw new Exception("获取支付宝 ACCESS_TOKEN 出错");
            }

            AlipayAccessTokenParamEntity alipayAccessToken = new AlipayAccessTokenParamEntity
            {
                timestamp  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                method     = "alipay.user.info.share",
                app_id     = param.app_id,
                sign_type  = "RSA2",
                version    = "1.0",
                charset    = "utf-8",
                auth_token = accessToken.alipay_system_oauth_token_response.access_token,
            };

            alipayAccessToken.sign = System.Web.HttpUtility.UrlEncode(Signature(alipayAccessToken));
            var url    = $"{AccessToken_Url}?{ParamUtil.BuildSortedParams(alipayAccessToken, false, "")}";
            var result = HttpUtil.Get(url);

            AlipayUserinfoEntity alipay_Userinfo = JsonConvert.DeserializeObject <AlipayUserinfoEntity>(result);

            if (alipay_Userinfo == null)
            {
                return("");
            }
            else
            {
                return(JsonConvert.SerializeObject(alipay_Userinfo));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 使用工具调试签名流程介绍 https://opensupport.alipay.com/support/helpcenter/286/201602644045?ant_source=antsupport
        /// </summary>
        /// <param name="alipayAccessToken"></param>
        /// <returns></returns>
        private string Signature(AlipayAccessTokenParamEntity alipayAccessToken)
        {
            //所有请求参数,不包括字节类型参数,如文件、字节流,剔除 sign 字段,剔除值为空的参数,
            //并按照第一个字符的键值 ASCII 码递增排序(字母升序排序),如果遇到相同字符则按照第二个字符的键值 ASCII 码递增排序,以此类推。
            var unsignString = ParamUtil.BuildSortedParams(alipayAccessToken);
            //私钥的绝对路径
            var privateKeyPemPath = GetCurrentPath() + "RSA2_private_key.txt";

            //加密。目前只考虑“普通公钥”方式
            return(RSASignCharSet(unsignString, privateKeyPemPath, "utf-8", "RSA2"));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// http直接访问 https://openapi.alipay.com/gateway.do?timestamp=2013-01-01 08:08:08&method=alipay.system.oauth.token&app_id=4472&sign_type=RSA2&sign=ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE&version=1.0&charset=GBK&grant_type=authorization_code&code=4b203fe6c11548bcabd8da5bb087a83b
        /// auth_code授权之后的回执
        /// </summary>
        /// <returns></returns>
        private AlipayAccessTokenEntity GetAccessToken()
        {
            AlipayAccessTokenParamEntity alipayAccessToken = new AlipayAccessTokenParamEntity
            {
                timestamp  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                method     = "alipay.system.oauth.token",
                app_id     = param.app_id,
                sign_type  = "RSA2",
                version    = "1.0",
                charset    = "utf-8",
                grant_type = "authorization_code",
                code       = HttpContext.Current.Request.QueryString["auth_code"],
                format     = "",
            };

            alipayAccessToken.sign = System.Web.HttpUtility.UrlEncode(Signature(alipayAccessToken));
            var url    = $"{AccessToken_Url}?{ParamUtil.BuildSortedParams(alipayAccessToken, false, "")}";
            var result = HttpUtil.Get(url);
            AlipayAccessTokenEntity alipay_AccessToken = JsonConvert.DeserializeObject <AlipayAccessTokenEntity>(result);

            return(alipay_AccessToken);
        }