WOSign API


[HttpGet]
public ActionResult WoSign()
{

// System.IO.FileStream fs = System.IO.File.OpenRead(System.Web.HttpContext.Current.Server.MapPath("~/Content/pp1.png"));//传文件的路径即可
// System.IO.BinaryReader br = new BinaryReader(fs);
// byte[] bt = br.ReadBytes(Convert.ToInt32(fs.Length));
// string base64String1 = Convert.ToBase64String(bt);
// br.Close();
// fs.Close();

var company= Convert.ToBase64String(System.IO.File.ReadAllBytes(System.Web.HttpContext.Current.Server.MapPath("~/Content/pp1.png")));
var user = Convert.ToBase64String(System.IO.File.ReadAllBytes(System.Web.HttpContext.Current.Server.MapPath("~/Content/pp2.png")));

var obj = new
{
tokenid = "0995d18b-6cf9-453247d-8a31-478c7e020828",
actiontype = "CreateSignOrder",
tempid = "956eb3a2-3ea3-4749-a33e-65767519eab4",
subject = "借款服务协议",
password = "",
filebase = "",
fileformat = "",
orderNumber = "324233243243225443632344234",
signerlist = new object[]

{
new {signType=1,orgName="融信城(上海)电子商务有限公司",orgNo="9134310109342191070G",stampbase="",pic="111",otherpic="22"},
new {signType = 2, userName = "李帅", userNo = "41282419963401083571",stampbase=user, pic = "41282413499601083571", otherpic = "345"}
}
};

var str = JsonConvert.SerializeObject(obj);
var result = PostMoths("https://docapitest.wosign.com/", str);

//var obj = new
//{
// tokenid = "0995d18b-6cf9-457d-8a31-478c7e020828",
// actiontype = "PushSignedDoc",
// status = 1,
// errorcode = 0,
// extendData = new
// {
// signid = "75829991-8076-4bb5-a0fb-55c5282f47ec",
// orderNumber = "44035241526352145"
// }

//};

//var str = JsonConvert.SerializeObject(obj);
//var result = PostMoths("https://docapitest.wosign.com/", str);

return Content(result);


}

[HttpPost]
public void WoSignPushSignedDoc()
{
Stream postData = Request.InputStream;
StreamReader sRead = new StreamReader(postData);
string postContent = sRead.ReadToEnd();
sRead.Close();

FileStream fs = new FileStream(System.Web.HttpContext.Current.Server.MapPath("~/Content/cc.txt"), FileMode.Create);

byte[] data = System.Text.Encoding.Default.GetBytes(postContent);

fs.Write(data, 0, data.Length);

fs.Flush();
fs.Close();

}

public static string PostMoths(string url, string param)
{
string strURL = url;
System.Net.HttpWebRequest request;
request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
X509Certificate cer = X509Certificate.CreateFromCertFile(System.Web.HttpContext.Current.Server.MapPath("~/App_Data/RXCWoSign.cer"));
request.ClientCertificates.Add(cer);
request.Method = "POST";
request.ContentType = "application/json;charset=UTF-8";
string paraUrlCoded = param;
byte[] payload;
payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
request.ContentLength = payload.Length;
Stream writer = request.GetRequestStream();
writer.Write(payload, 0, payload.Length);
writer.Close();
System.Net.HttpWebResponse response;
response = (System.Net.HttpWebResponse)request.GetResponse();
System.IO.Stream s;
s = response.GetResponseStream();
string StrDate = "";
string strValue = "";
StreamReader Reader = new StreamReader(s, Encoding.UTF8);
while ((StrDate = Reader.ReadLine()) != null)
{
strValue += StrDate + "\r\n";
}
return strValue;
}

public void test()
{
string base64BinaryStr = "";

byte[] sPDFDecoded = Convert.FromBase64String(base64BinaryStr);

BinaryWriter writer = new BinaryWriter(System.IO.File.Open(@"F:5.pdf", FileMode.CreateNew));
writer.Write(sPDFDecoded);
string s = Encoding.UTF8.GetString(sPDFDecoded);

}

posted @ 2017-01-13 10:13  SpringLeee  阅读(187)  评论(0编辑  收藏  举报