public RstArray ApiPay(string script_name, Dictionary <string, string> param, Dictionary <string, string> cookie, string method, string protocol) { RstArray result_array = new RstArray(); // 生成签名 string secret = appkey + "&"; string sig = SnsSigCheck.MakeSig(method, script_name, param, secret); param.Add("sig", sig); string url = protocol + "://" + server_name + script_name; //通过调用以下方法,可以打印出最终发送到openapi服务器的请求参数以及url,不打印可以注释 PrintRequest(url, param, method); // 发起请求 result_array = SnsNetWork.MakeRequest(url, param, cookie, method, protocol); if (result_array.Ret != 0) { result_array.Ret += OPENAPI_ERROR_HTPP; return(result_array); } //解析返回结果的返回码 string stat_ret = ""; try { if (this.format == "xml") { XmlDocument xml = new XmlDocument(); xml.LoadXml(result_array.Msg); stat_ret = xml.LastChild["ret"].InnerText.ToString(); } else { JavaScriptSerializer serializer = new JavaScriptSerializer(); RstArray json_obj = new RstArray(); json_obj = serializer.Deserialize <RstArray>(result_array.Msg); stat_ret = json_obj.Ret.ToString(); } } catch (Exception e) { result_array.Msg = e.Message; // 远程返回的不是 json或者xml 格式, 说明返回包有问题 result_array.Ret += OPENAPI_ERROR_RESPONSE_DATA_INVALID; return(result_array); } //通过调用以下方法,可以打印出调用openapi请求的返回码以及错误信息,不打印可以注释 PrintRespond(result_array); return(result_array); }
public RstArray ApiMsdk(string script_name, Dictionary <string, string> param, Dictionary <string, string> qs, string method, string protocol) { RstArray result_array = new RstArray(); string uri = SnsNetWork.MakeQueryString(qs); script_name = script_name + "?" + uri; string url = protocol + "://" + server_name + script_name; Dictionary <string, string> cookie = new Dictionary <string, string>(); //通过调用以下方法,可以打印出最终发送到openapi服务器的请求参数以及url,不打印可以注释 PrintRequest(url, param, method); ParamJson paramj = new ParamJson { appid = param["appid"], openid = param["openid"], openkey = param["openkey"], userip = param["userip"] }; string param_json = JsonConvert.SerializeObject(paramj); // 发起请求 result_array = SnsNetWork.MakeRequest(url, param_json, cookie, method, protocol); if (result_array.Ret != 0) { result_array.Ret += OPENAPI_ERROR_HTPP; return(result_array); } //解析返回结果的返回码 string stat_ret = ""; try { if (this.format == "xml") { XmlDocument xml = new XmlDocument(); xml.LoadXml(result_array.Msg); stat_ret = xml.LastChild["ret"].InnerText.ToString(); } else { JavaScriptSerializer serializer = new JavaScriptSerializer(); RstArray json_obj = new RstArray(); json_obj = serializer.Deserialize <RstArray>(result_array.Msg); stat_ret = json_obj.Ret.ToString(); } } catch (Exception e) { result_array.Msg = e.Message; // 远程返回的不是 json或者xml 格式, 说明返回包有问题 result_array.Ret += OPENAPI_ERROR_RESPONSE_DATA_INVALID; return(result_array); } //通过调用以下方法,可以打印出调用openapi请求的返回码以及错误信息,不打印可以注释 PrintRespond(result_array); return(result_array); }