public void Predict(FateadmRsp rsp, string app_id, string app_key, string usr_id, string usr_key, string pred_type, byte[] img_data) { string cur_tm = GetCurrentTimeUnix(); string sign = CalcSign(usr_id, usr_key, cur_tm); IDictionary <string, string> param = new Dictionary <string, string>(); param.Add("user_id", usr_id); param.Add("timestamp", cur_tm); param.Add("sign", sign); param.Add("up_type", "mt"); if (!string.IsNullOrEmpty(app_id)) { string asign = CalcSign(app_id, app_key, cur_tm); param.Add("appid", app_id); param.Add("asign", asign); } param.Add("predict_type", pred_type); string url = URL + "/api/capreg"; HttpRspData jrsp = null; jrsp = PostMForm(url, param, img_data); rsp.ret_code = int.Parse(jrsp.RetCode); rsp.err_msg = jrsp.ErrMsg; rsp.order_id = jrsp.RequestId; if (rsp.ret_code == 0) { rsp.pred_reslt = jrsp.einfo.result; } }
public static void Predict(FateadmRsp rsp, string app_id, string app_key, string usr_id, string usr_key, string pred_type, byte[] img_data) { string cur_tm = GetCurrentTimeUnix(); string sign = CalcSign(usr_id, usr_key, cur_tm); IDictionary <string, string> param = new Dictionary <string, string>(); param.Add("user_id", usr_id); param.Add("timestamp", cur_tm); param.Add("sign", sign); if (!string.IsNullOrEmpty(app_id)) { string asign = CalcSign(app_id, app_key, cur_tm); param.Add("appid", app_id); param.Add("asign", asign); } param.Add("predict_type", pred_type); string b64data = Convert.ToBase64String(img_data, 0, img_data.Length); param.Add("img_data", HttpUtility.UrlEncode(b64data)); string url = URL + "/api/capreg"; HttpRspData jrsp = HttpPost(url, param); rsp.ret_code = int.Parse(jrsp.RetCode); rsp.err_msg = jrsp.ErrMsg; rsp.order_id = jrsp.RequestId; if (rsp.ret_code == 0) { rsp.pred_reslt = jrsp.einfo.result; } }
public static void Justice(FateadmRsp rsp, string usr_id, string usr_key, string order_id) { string cur_tm = GetCurrentTimeUnix(); string sign = CalcSign(usr_id, usr_key, cur_tm); IDictionary <string, string> param = new Dictionary <string, string>(); param.Add("user_id", usr_id); param.Add("timestamp", cur_tm); param.Add("sign", sign); param.Add("request_id", order_id); string url = URL + "/api/capjust"; HttpRspData jrsp = HttpPost(url, param); rsp.ret_code = int.Parse(jrsp.RetCode); rsp.err_msg = jrsp.ErrMsg; }
public static void Charge(FateadmRsp rsp, string usr_id, string usr_key, string cardid, string cardkey) { string cur_tm = GetCurrentTimeUnix(); string sign = CalcSign(usr_id, usr_key, cur_tm); string csign = Md5(usr_key + cur_tm + cardid + cardkey); IDictionary <string, string> param = new Dictionary <string, string>(); param.Add("user_id", usr_id); param.Add("timestamp", cur_tm); param.Add("sign", sign); param.Add("cardid", cardid); param.Add("csign", csign); string url = URL + "/api/charge"; HttpRspData jrsp = HttpPost(url, param); rsp.ret_code = int.Parse(jrsp.RetCode); rsp.err_msg = jrsp.ErrMsg; rsp.order_id = jrsp.RequestId; }
public static void QueryBalc(FateadmRsp rsp, string usr_id, string usr_key) { string cur_tm = GetCurrentTimeUnix(); string sign = CalcSign(usr_id, usr_key, cur_tm); IDictionary <string, string> param = new Dictionary <string, string>(); param.Add("user_id", usr_id); param.Add("timestamp", cur_tm); param.Add("sign", sign); string url = URL + "/api/custval"; HttpRspData jrsp = HttpPost(url, param); rsp.ret_code = int.Parse(jrsp.RetCode); rsp.err_msg = jrsp.ErrMsg; if (rsp.ret_code == 0) { rsp.cust_val = jrsp.einfo.cust_val; } }
public static HttpRspData HttpPost(string url, IDictionary <string, string> param) { //string url = ""; Encoding charset = Encoding.GetEncoding("utf-8"); //IDictionary<string, string> param = new Dictionary<string, string>(); //param.Add("usrid", "10000"); HttpWebResponse resp = CreatePostHttpResponse(url, param, charset); Stream stream = resp.GetResponseStream(); //获取响应的字符串流 StreamReader sr = new StreamReader(stream); //创建一个stream读取流 string html = sr.ReadToEnd(); //从头读到尾,放到字符串html //Console.WriteLine(html); HttpRspData data = JsonPaserWeb.Deserialize <HttpRspData>(html); if (!string.IsNullOrEmpty(data.RspData)) { // 附带附加信息 HttpExtraInfo einfo = JsonPaserWeb.Deserialize <HttpExtraInfo>(data.RspData); data.einfo = einfo; } return(data); }
static HttpRspData PostMForm(string url, IDictionary <string, string> param, byte[] img_data) { string boundary = "-----" + DateTime.Now.Ticks.ToString("x"); byte[] boundarybytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n"); HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url); wr.ContentType = "multipart/form-data; boundary=" + boundary; wr.UserAgent = "RK_C# 1.2"; wr.Method = "POST"; Stream rs = null; try { rs = wr.GetRequestStream(); } catch { Console.WriteLine("The Web is Disconnected!"); return(null); } string html = null; string item_string = "Content-Disposition: form-data; name=\"{0}\"\r\n\r\n{1}"; foreach (string key in param.Keys) { rs.Write(boundarybytes, 0, boundarybytes.Length); string form_item = string.Format(item_string, key, param[key]); //Console.WriteLine(string.Format("key:{0} val:{1}",key,param[key])); byte[] form_item_bytes = System.Text.Encoding.UTF8.GetBytes(form_item); rs.Write(form_item_bytes, 0, form_item.Length); } rs.Write(boundarybytes, 0, boundarybytes.Length); string file_srtring = string.Format("Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\nContent-Type: {2}\r\n\r\n" , "img_data", "image", "image/jpg"); rs.Write(System.Text.Encoding.UTF8.GetBytes(file_srtring), 0, file_srtring.Length); rs.Write(img_data, 0, img_data.Length); byte[] trail = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "--"); rs.Write(trail, 0, trail.Length); rs.Close(); WebResponse wresp = null; HttpRspData data = null; try { wresp = wr.GetResponse(); Stream stream2 = wresp.GetResponseStream(); StreamReader reader2 = new StreamReader(stream2); html = reader2.ReadToEnd(); } catch { } finally { if (wresp != null) { wresp.Close(); wresp = null; data = JsonPaserWeb.Deserialize <HttpRspData>(html); if (!string.IsNullOrEmpty(data.RspData)) { // 附带附加信息 HttpExtraInfo einfo = JsonPaserWeb.Deserialize <HttpExtraInfo>(data.RspData); data.einfo = einfo; } } wr.Abort(); wr = null; } return(data); }