Example #1
0
        /// <summary>
        /// 获取授权码
        /// 当使用app_auth_code换取app_auth_token时,biz_content的内容如下:
        ///{
        ///    "grant_type": "authorization_code",
        ///    "code": "bf67d8d5ed754af297f72cc482287X62"
        ///}
        /// 当要刷新app_auth_token时,需要使用refresh_token,biz_content的内容如下:
        ///{
        ///    "grant_type": "refresh_token",
        ///    "refresh_token": "201510BB0c409dd5758b4d939d4008a525463X62"
        ///}
        /// </summary>
        /// <returns></returns>
        public AlipayOpenAuthTokenAppResponse OpenAuthTokenApp(OpenAuthTokenAppDTO dto)
        {
            AlipayOpenAuthTokenAppRequest request = new AlipayOpenAuthTokenAppRequest();

            request.BizContent = dto.BuildJson();
            AlipayOpenAuthTokenAppResponse response = client.Execute(request);

            return(response);
        }
Example #2
0
File: AliPayAPI.cs Project: qdjx/C5
    public static AlipayOpenAuthTokenAppResponse alipay_open_auth_token_app(string code)
    {
        var client = GetAlipayClient();
        AlipayOpenAuthTokenAppRequest request = new AlipayOpenAuthTokenAppRequest();

        request.BizContent = "{\"grant_type\":\"authorization_code\",\"code\":\"" + code + "\"}";
        AlipayOpenAuthTokenAppResponse response = client.Execute(request);

        return(response);
    }
Example #3
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            string app_id        = context.Request["app_id"];
            string app_auth_code = context.Request["app_auth_code"];

            Hashtable ht = new Hashtable();

            ht["App_id"]        = app_id;
            ht["App_auth_code"] = app_auth_code;

            string serverUrl            = Config.serverUrl;
            string merchant_private_key = Config.merchant_private_key;
            string format            = "json";
            string version           = Config.version;
            string signType          = Config.signtype;
            string alipay_public_key = Config.alipay_public_key;
            string charset           = Config.charset;

            IAopClient client = new DefaultAopClient(serverUrl, app_id, merchant_private_key, format, version, signType, alipay_public_key, charset, false);

            AlipayOpenAuthTokenAppRequest request = new AlipayOpenAuthTokenAppRequest();

            request.BizContent = "{" +
                                 "    \"grant_type\":\"authorization_code\"," +
                                 "    \"code\":\"" + app_auth_code + "\"" +
                                 "  }";
            AlipayOpenAuthTokenAppResponse response = client.Execute(request);

            //IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", "app_id", "merchant_private_key", "json", "1.0", "RSA2", "alipay_public_key", "GBK", false);
            //AlipayOpenAuthTokenAppRequest request = new AlipayOpenAuthTokenAppRequest();
            //request.BizContent = "{" +
            //"\"grant_type\":\"authorization_code或者refresh_token\"," +
            //"\"code\":\"1cc19911172e4f8aaa509c8fb5d12F56\"," +
            //"\"refresh_token\":\"201509BBdcba1e3347de4e75ba3fed2c9abebE36\"" +
            //"  }";
            //AlipayOpenAuthTokenAppResponse response = client.execute(request);
            //Console.WriteLine(response.Body);

            if (response != null)
            {
                if (!string.IsNullOrEmpty(response.AppAuthToken))
                {
                    ht["AppAuthToken"] = response.AppAuthToken;
                }
                if (!string.IsNullOrEmpty(response.AppRefreshToken))
                {
                    ht["AppRefreshToken"] = response.AppRefreshToken;
                }
                if (!string.IsNullOrEmpty(response.AuthAppId))
                {
                    ht["AuthAppId"] = response.AuthAppId;
                }
                if (!string.IsNullOrEmpty(response.ExpiresIn))
                {
                    ht["ExpiresIn"] = response.ExpiresIn;
                }
                if (!string.IsNullOrEmpty(response.ReExpiresIn))
                {
                    ht["ReExpiresIn"] = response.ReExpiresIn;
                }
                if (!string.IsNullOrEmpty(response.UserId))
                {
                    ht["UserId"] = response.UserId;
                }
                string body = response.Body;
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                alipay alipayInfo = serializer.Deserialize <alipay>(body);
                if (alipayInfo != null && alipayInfo.alipay_open_auth_token_app_response != null && alipayInfo.alipay_open_auth_token_app_response.tokens != null && alipayInfo.alipay_open_auth_token_app_response.tokens.Count() > 0)
                {
                    token info = alipayInfo.alipay_open_auth_token_app_response.tokens[0];
                    ht["AppAuthToken"]    = info.app_auth_token;
                    ht["AppRefreshToken"] = info.app_refresh_token;
                    ht["AuthAppId"]       = info.auth_app_id;
                    ht["ExpiresIn"]       = info.expires_in;
                    ht["ReExpiresIn"]     = info.re_expires_in;
                    ht["UserId"]          = info.user_id;
                }
            }

            DataFactory.SqlDataBase().InsertByHashtable("Alipay_PlatformUser", ht);

            context.Response.Write("success");
            return;
        }