Skip to content

Instantly share code, notes, and snippets.

@leeight
Last active March 15, 2016 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leeight/2ff85e853c5472a4aa55 to your computer and use it in GitHub Desktop.
Save leeight/2ff85e853c5472a4aa55 to your computer and use it in GitHub Desktop.
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