1.調用統一下單接口驗簽失敗
https://pay.weixin.qq.com/wiki/doc/api/app.php?chapter=9_1
開始的時候是string Format格式填寫參數,錯。後來翻看其他博客和微信demo,才得知應該這樣寫:
//將數據添加到字典中
SortedDictionary<string, string> m_values = new SortedDictionary<string, string>();
m_values.Add("appid", appID);
m_values.Add("body", bodymsg);
m_values.Add("mch_id", mch_id);
m_values.Add("nonce_str", nonce_str);
m_values.Add("notify_url", notify_url);
m_values.Add("openid", openID);
m_values.Add("out_trade_no", orderId);
m_values.Add("spbill_create_ip", spbill_create_ip);
m_values.Add("total_fee", total_fee.ToString());
m_values.Add("trade_type", "JSAPI");
string signkey = WXDes.TotUrl(m_values); //拼接數據
//拼接字符串key=value
public static string TotUrl(SortedDictionary<string, string> m_values)
{
int i = 0;
StringBuilder sb = new StringBuilder();
foreach (KeyValuePair<string, string> temp in m_values)
{
if (temp.Value == "" || temp.Value == null || temp.Key.ToLower() == "sign")
{
continue;
}
i++;
sb.Append(temp.Key.Trim() + "=" + temp.Value.Trim() + "&");
}
sb.Append("key=" + ConfigHelp.APISign);
string signkey = sb.ToString();
return signkey;
}
2.調用統一下單 body編碼問題
剛開始編寫是直接body="你好"直接賦值的,但是微信返回碼說沒有UTF-8編碼,然後又HttpUtility.UrlEncode("會員充值", Encoding.GetEncoding("UTF-8")),結果支付頁面顯示編碼後的文字,然後看到帖子說直接賦值就ok,又一直,果真!!!!
body="直接賦值"
3.API輸入密碼框頁面無法顯示
拿到微信返回的prepay_id,訪問API接口,是將生成的json返回到前端,alert(json字符串)沒有任何問題,傳入微信就報缺少參數,幾經周折
如此將返回json轉換一下 JSON.parse(json)