php的http_build_query不得不说很好用,用c#实现它,过程稍长
http_build_query方法:
public static string http_build_query(Dictionary<string, string> dict = null)
{
if (dict == null)
{
return "";
}
string QueryString=string.Empty;
foreach (KeyValuePair<string, string> kvp in dict)
{
QueryString = QueryString + HttpUtility.UrlEncode(kvp.Key) + "=" + HttpUtility.UrlEncode(kvp.Value) + "&";
}
QueryString = QueryString.Substring(0, QueryString.Length - 1);
return QueryString;
}
调用过程:
protected void testhttp_build_query_Click(object sender, EventArgs e)
{
try
{
string secret = "1e7f7231-12b1-86ec"; //密钥
var DataDictionary = new Dictionary<string, string>();
DataDictionary.Add("currency", "HKD");
DataDictionary.Add("amount", "100");
DataDictionary.Add("return_url", "www.baidu.com/api"); //显示支付成功的界面,应该做多一个页面叫payment_return.aspx
DataDictionary.Add("customer_first_name", "stephen");
DataDictionary.Add("customer_last_name", "");
DataDictionary.Add("customer_address", "");
DataDictionary.Add("customer_phone", "90472886");
DataDictionary.Add("customer_email", "");
DataDictionary.Add("customer_state", "");
DataDictionary.Add("customer_country", "CN");
DataDictionary.Add("network", "alipay");
DataDictionary.Add("subject", "Jiyun Fee");
Dictionary<string, string> dic_SortedByKey = DataDictionary.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value); //对key排从小到大的升序,类似php ksort($fields);
var strrrrr = http_build_query(dic_SortedByKey);
showDesString.Text = strrrrr;
}
catch (Exception err)
{
Response.Write(err.Message);
}
}
原文转载:http://www.shaoqun.com/a/497226.html
cbo:https://www.ikjzd.com/w/2670
阿里巴巴 批发:https://www.ikjzd.com/w/1084
hts:https://www.ikjzd.com/w/525
php的http_build_query不得不说很好用,用c#实现它,过程稍长http_build_query方法:publicstaticstringhttp_build_query(Dictionary<string,string>dict=null){if(dict==null){return"";}stringQueryString=string.Empty
联动优势电子商务:联动优势电子商务
赛兔:赛兔
全球"十大最安全国家"出炉 冰岛居首位:全球"十大最安全国家"出炉 冰岛居首位
华南植物园五一免费吗?五一广州华南植物园门票优惠吗?:华南植物园五一免费吗?五一广州华南植物园门票优惠吗?
【英国旅游著名景点】--英国有哪些旅游著名景点:【英国旅游著名景点】--英国有哪些旅游著名景点
No comments:
Post a Comment