SpringBoot實現小程式微信支付統一下單

2021-10-21 20:52:50 字數 2670 閱讀 4896

@service

public class wxpayserviceimpl implements wxpayservice

//把引數放在map中,準備進行簽名加密

mapmaps = new hashmap<>();

maps.put("openid", openid);

maps.put("mch_id", mch_id);

maps.put("nonce_str", nonce_str);

maps.put("body", body);

maps.put("out_trade_no", out_trade_no);

maps.put("total_fee", string.valueof(total_fee));

maps.put("trade_type", trade_type);

maps.put("notify_url", notify_url);

string spbill_create_ip = null;

string sign = null;

try catch (exception e)

//拼接需要傳送引數

+ "" + "" + mch_id + "" + ""

+ nonce_str + "" + "" + notify_url

+ "" + "" + out_trade_no

+ "" + "" + spbill_create_ip

+ "" + "" + total_fee

+ "" + "" + trade_type

+ "" + "" + sign + "" + ""

+ openid + "" + "";

/* api位址 */

string url = "";

mapresultmaps = new hashmap<>();

string result =null;

try catch (exception e)

resultmaps = xmlstrtomap(result);//返回結果是xml字串,轉換成map

//將統一下單返回的引數進行二次簽名加密

if(resultmaps.get("result_code").equals("success")&&resultmaps.get("return_code").equals("success")) catch (exception e)

//已準備好wx.requestpayment所需要的引數,返回引數給前端拉起支付!

mapovermap = new hashmap<>();

overmap.put("timestamp", timestamp);

overmap.put("noncestr", noncestr);

overmap.put("package", package1);

overmap.put("signtype", "md5");

overmap.put("paysign", paysign);

return overmap;

}else

}/* 傳送統一下單請求 */

public string fasong(string xmlinfo, string url) throws exception

reader.close();

// 該幹的都幹完了,記得把連線斷了

connection.disconnect();

return resultlin;

}/* string轉為map */

public mapxmlstrtomap(string xmlstr)

}} catch (exception e)

return map;

}/* 隨機生成32位字元 */

public string getram() ;

stringbuffer pwd = new stringbuffer("");

random r = new random();

while (count < 32)

}system.out.println(pwd.tostring());

return pwd.tostring();

}/* 簽名加密 */

public string qianming(string secretkey, mapmaps)

throws unsupportedencodingexception

// 3. 將secretkey拼接到最後

system.out.println(parambuffer);

string pa = parambuffer.substring(1);

// 4. md5是128位長度的摘要演算法,用16進製表示,乙個十六進製制的字元能表示4個位,所以簽名後的字串長度固定為32個十六進製制字元。

//return digestutils.md5hex(pa.getbytes("utf-8")).touppercase();

return digestutils.md5digestashex(pa.getbytes("utf-8")).touppercase();

}/* 獲取ip位址 */

public string getip() throws exception

}

python實現小程式 python實現小程式

1 楊輝三角形python實現 1 11 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 楊輝三角形 def triangel n l 1 定義乙個list 1 while true yield l 列印出該list l l x l x 1 for x in range le...

python實現小程式

1 楊輝三角形python實現 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 楊輝三角形 def triangel n l 1 定義乙個list 1 while true yield l 列印出該list l l x l x 1 for x in range...

Python實現聊天小程式

import socket import sys host port 10001 server socket socket.socket socket.af inet,socket.sock stream server socket.setsockopt socket.sol socket,sock...