一直报签名失败,查了所有的参数,用了三种写法,得到的签名结果是一样的,但微信返回一直是签名失败。
@SpringBootTest
public class WxPayTests {
@Resource
CloudWXPayConfig config;
@Test
public void setupTest() throws Exception{
String randStr = WXPayUtil.generateNonceStr();
System.out.println(randStr+ "," + randStr.length());
Map<String,String> map = new HashMap<>(16);
map.put("appid",config.getAppID()); //公众账号ID
map.put("mch_id",config.getMchID()); // 商户号
map.put("nonce_str",randStr); // 随机字符串
map.put("body","第一时间科技投资股份有限公司-零售"); // 商品描述
// map.put("sign_type", "HMAC-SHA256");
map.put("out_trade_no","hqj1234567890"); // 商户订单号
map.put("total_fee","11"); // 订单金额
map.put("spbill_create_ip","101.93.21.216"); // 终端IP
map.put("auth_code","134924747267206519"); //付款码
String tmp = WXPayUtil.mapToXml(map);
System.out.println(tmp);
String str = Signature.getOrderedMapString(map);
System.out.println(str);
// WXPayConfig config = new MyWXPayConfig(wxAppid,wxMchId,wxKey,wxDomain);
String signature= WXPayUtil.generateSignature(map,config.getKey());
System.out.println(signature);
map.put("sign",signature);
System.out.println(WXPayUtil.mapToXml(map));
WXPay wx = new WXPay(config);
String result = null;
try{
Map<String,String> resp = wx.microPay(map);
result = WXPayUtil.mapToXml(resp);
System.out.println(resp);
}catch(Exception e){
e.printStackTrace();
System.out.println("failed:" + e.getMessage());
}
}
}