Last active
March 15, 2016 08:09
-
-
Save leeight/2ff85e853c5472a4aa55 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using System.Web.Mvc; | |
using System.Web.Mvc.Ajax; | |
using BaiduBce; | |
using BaiduBce.Auth; | |
using BaiduBce.Internal; | |
using Newtonsoft.Json; | |
using BaiduBce.Util; | |
namespace BaiduCloudEngine.Controllers | |
{ | |
class SignatureResult { | |
public int statusCode { get; set; } | |
public string signature { get; set; } | |
public string xbceDate { get; set; } | |
} | |
public class HomeController : Controller | |
{ | |
public string Index(string httpMethod, string path, string queries, string headers, string callback) { | |
BceClientConfiguration config = new BceClientConfiguration(); | |
config.Credentials = new DefaultBceCredentials("AK", "SK"); | |
BceV1Signer bceV1Signer = new BceV1Signer(); | |
InternalRequest internalRequest = new InternalRequest(); | |
internalRequest.Config = config; | |
internalRequest.Uri = new Uri("http://www.baidu.com" + path); | |
internalRequest.HttpMethod = httpMethod; | |
if (headers != null) { | |
internalRequest.Headers = JsonConvert.DeserializeObject> (headers); | |
} | |
if (queries != null) { | |
internalRequest.Parameters = JsonConvert.DeserializeObject> (queries); | |
} | |
var sign = bceV1Signer.Sign(internalRequest); | |
var xbceDate = DateUtils.FormatAlternateIso8601Date (DateTime.Now); | |
var result = JsonConvert.SerializeObject (new SignatureResult() { | |
statusCode = 200, | |
signature = sign, | |
xbceDate = xbceDate | |
}); | |
if (callback != null) { | |
result = callback + "(" + result + ")"; | |
} | |
return result; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment