Esempio n. 1
0
        public IActionResult Test()
        {
            DefaultAopClient client = new DefaultAopClient("https://openapi.alipaydev.com/gateway.do", "2016090800466366", "MIIEogIBAAKCAQEAuCcfh+EJHfMwzXC6b8HfzjYDcH7y79dKAdh5Y5rXOO/4y9stKke+F4Pdp7BOzu6N8/jse7xxCiVLdyUO0L/ck5hOWna//fdQPcSbEyYBUQn+CQy7+uDbsZRniXeeaHJBnK5fot3oHzpHe4dScnvG5NKRJAYsaQW5vD8cVc/m31yuocbyPgqUllblK3h8Lg/nh64bKl8e0Hck1EgGm7+W0+IojM9rcMY1BrdIlUiuP25u8I3zPFH5Tjk4otCvm+xDsukeJiftmDrhtmW3cGtTpNFtr6DK+acfNVccyiaGeCidvLcT3ziO8V7Cy1oQVk+8j5qg83xzCslvF0kZwwrQXwIDAQABAoIBAErfbUx7zI8mz5LX4JWLyAk5oNBebTvi1q5Fa6V50UPPHeMUrBpirQE2liqV3pT4HTMy5EOy7GrpmvNIV+u79lz0MfdKDOmfYjqa80ony6U9YNIhIVTxk6Fx617TCc8BlXe01iGMA9KeiW3KKVVuygFDM8vnzqqsr0XAiy7ApuftP4ujFCJhDZ/PSaKB1/YNJQjz/2GRjqbYT5irre3Mjz7FgyN19CJmSnjshdixp0ItOTQ7QsHYE537gGZhEXs+RDFopF+w4y45kfUUh1IpBxD7jlD1zO3OHXJxBqSiJxz4iO8FS/OYdQUMoGpTtJc6bMnmZcLSwnfV9RTIB381BoECgYEA7+AcpfIpKWgc1zOJRKTjBdKe77LTjto30UlyeskpUofKVRqEYTgALL7POlH16L9gA2R8HvsSEmAPGw7P4ptYO+Kfi3TeiG6RwT5K+JSB8g0xqwvDEVOD3May+nfnaz5sMktWNirSFHbbymfh99mj+4E1drv3cOuDJR6v2qicTyECgYEAxIgcUkcG6CpHagxYfaboyvmglbq/9ZD+ruZSvqG877NT0NLqEPZ6ZOd6AS9m/GsC6pUABtFfXK256oZ7H8bqsfIFTfoUbjiy3fXNuniuvqtLTGL+2kyCazhV15kLtX24wCV6M32Yc1DvGPywAI40UG9D6D2MTCuu7KgO715or38CgYA9p8AVU0oLL4yCL+fvceY8X+ekOrWv+RzxuUwojT4GzYpPF5LBHlDFL4I6PkjTuyTlmlVg7S229WPMk6ERYNZsBhL2GGL+dFUYc3d3r0w7N/L1QP+xm2LAQ35LbLhZ02CiCMUvBRCcW/SgcNUfDJzej1Z7n1K5fn9l8h5HOKF8oQKBgBP7Hp4C2KHsAny2qpyDxrE0Ne5jITcPOcWAZzM4cGQSYFgfyWpWFNWDbzUFo7vQCWjeIzWOPdrHUtqUN5pgd+YFjCKEZWVbYFwOrI7jzChYc/xdKDn7g1rxTFDyH22hTZJDfSwU/dXjiZuJvT8hNhJjbY0EDOqFmnA3GeWePJhzAoGAXioZrM79oG/iN59XuAA5Arl5UjkCsKPa1rfALCSfEoJfvH1UAQ1SbuM0MMIAOGJc/yPdDjyv8Kdy7z867gxo6m0vuLdyJ6qL/KI//mNLJpW30I6/pYsWO1LIIxusxTkv459mvGufn1WH0LHpAf4b84/uq2EDszVat7MEt48NlSI=", "json", "2.0",
                                                           "RSA2", "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyWWqIIJ0KKDUPk6fgbxXLxCDqVWTvV4mplocxRsjFPvZC2e4uHs6hq3n8/bc/ZnLcavDTCx56L+TsTKN8w4984pqYPgkYXjWl26hMvVJ2GizjRGw+FeM+1uqiWzrDflX3Cp/o8HKSeFqjA+HXpX+nFg94XJfYIAf8vtHKCusdJE6YRmUZ7lCYH01M59b3KQBeX2q304GwC27xgZ1ZOuqGdngNeeTo0WgTpfKOzgQkUVDNLjVJhxk6i71vzfJ5QUUVIEff1UNlLK1C/kCGDaSY8DGPXni+BfdQekVxdqO1aV5JvaZVW9KrxnXfyAf0FYelBbqym4qzJu98+8eee/oyQIDAQAB", "UTF-8", false);

            var model = new AlipayOpenAuthTokenAppModel
            {
                //如果使用app_auth_code换取token,则为authorization_code,如果使用refresh_token换取新的token,则为refresh_token
                GrantType = "authorization_code",
                //与refresh_token二选一,用户对应用授权后得到,即第一步中开发者获取到的app_auth_code值
                Code = "ab64829e4d5b4e2aabd2ab6bae0dcB72",
                //与code二选一,可为空,刷新令牌时使用
                RefreshToken = ""
            };

            AlipayOpenAuthTokenAppRequest request = new AlipayOpenAuthTokenAppRequest();

            request.SetBizModel(model);

            request.SetReturnUrl("");

            var response = client.Execute(request);

            return(new JsonResult(new { data = response }));
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
File: AliPayAPI.cs Progetto: 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);
    }
Esempio n. 4
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;
        }