微信支付時候資料簽名 解析 請求demo

2021-08-01 04:46:30 字數 2043 閱讀 7482

public static string createsign(sortedmap<

string,string

> parameters,string private_key)

}+ private_key);//最後加密時新增商戶金鑰,由於key值放在最後,所以不用新增到sortmap裡面去,單獨處理,編碼方式採用utf-8

string sign = md5encode(sb.tostring(),"utf-8").touppercase();

return sign;

}

//我把md5加密也貼上吧。具體不細說

public

static string md5encode(string origin, string charsetname) catch (exception exception)

return resultstring;

}private

static

final string hexdigits = ;

private

static string bytearraytohexstring(byte b)

private

static string bytetohexstring(byte b)

//將封裝好的引數轉換成xml格式型別的請求字串

//簽名要放到所有引數的最後面

//attach欄位和body欄位需要轉義。sign也需要轉義

public static string getrequestxml(sortedmap<

string,string

> parameters)

else

if ("attach"

.equalsignorecase(k)||

"body"

.equalsignorecase(k))

else

}+"sign"

+">"+"

+parameters.get("sign")+

"]]>

+"sign"

+">");

return sb.tostring();

}

public static map

<

string,string

> doxmlparse(string strxml)

strxml = strxml.replacefirst("encoding=\".*\"", "encoding=\"utf-8\"");

map<

string,string

> m =

new hashmap<

string,string

>();

inputstream in

=new bytearrayinputstream(strxml.getbytes("utf-8"));

saxbuilder builder =

new saxbuilder();

document doc = builder.build(in);

element root = doc.getrootelement();

list

list

= root.getchildren();

iterator it =

list

.iterator();

while (it.hasnext()) else

m.put(k, v);

}// 關閉流

in.close();

return m;

}

//獲取子結點的xml 

private static string getchildrentext(list children)

+ name +

">");}}

return sb.tostring();

}

請笑納

php微信生成簽名 php 微信支付簽名快速生成

陣列轉xml可以封裝到common中,重要 以下2行 排序 ksort post 生成sign 全部 統一下單介面 public function unifiedorder wechat this wechat model getactive 從配置檔案或資料庫獲取資訊 post array pos...

php微信生成簽名 php 微信支付簽名快速生成

陣列轉xml可以封裝到common中,重要 以下2行 排序 ksort post 生成sign 全部 統一下單介面 public function unifiedorder wechat this wechat model getactive 從配置檔案或資料庫獲取資訊 post array pos...

微信支付 簽名錯誤問題

首先 看到返回msg顯示簽名錯誤 第一反應官網提供的路徑去生成了一下簽名做比較 結果發現簽名演算法是沒錯的.2 重置商戶api金鑰。本人親測是這樣解決了問題,tx真是個坑,我嚴重鄙視。4 引數body含有中文字元,改換英文簽名成功,那麼就轉換字元編碼試試。dat iconv utf 8 iso885...