2424 * 微信支付接口请求抽象实现类
2525 * Created by Binary Wang on 2017-7-8.
2626 * </pre>
27+ *
2728 * @author <a href="https://github.com/binarywang">Binary Wang</a>
2829 */
2930public abstract class WxPayServiceAbstractImpl implements WxPayService {
@@ -196,6 +197,8 @@ public Map<String, String> getPayInfo(WxPayUnifiedOrderRequest request) throws W
196197 }
197198
198199 Map <String , String > payInfo = new HashMap <>();
200+ String timestamp = String .valueOf (System .currentTimeMillis () / 1000 );
201+ String nonceStr = String .valueOf (System .currentTimeMillis ());
199202 if ("NATIVE" .equals (request .getTradeType ())) {
200203 payInfo .put ("codeUrl" , unifiedOrderResult .getCodeURL ());
201204 } else if ("APP" .equals (request .getTradeType ())) {
@@ -207,26 +210,27 @@ public Map<String, String> getPayInfo(WxPayUnifiedOrderRequest request) throws W
207210 configMap .put ("prepayid" , prepayId );
208211 configMap .put ("partnerid" , partnerid );
209212 configMap .put ("package" , "Sign=WXPay" );
210- configMap .put ("timestamp" , String . valueOf ( System . currentTimeMillis () / 1000 ) );
211- configMap .put ("noncestr" , String . valueOf ( System . currentTimeMillis ()) );
213+ configMap .put ("timestamp" , timestamp );
214+ configMap .put ("noncestr" , nonceStr );
212215 configMap .put ("appid" , appId );
213216 // 此map用于客户端与微信服务器交互
214217 payInfo .put ("sign" , SignUtils .createSign (configMap , this .getConfig ().getMchKey ()));
215218 payInfo .put ("prepayId" , prepayId );
216219 payInfo .put ("partnerId" , partnerid );
217220 payInfo .put ("appId" , appId );
218221 payInfo .put ("packageValue" , "Sign=WXPay" );
219- payInfo .put ("timeStamp" , String . valueOf ( System . currentTimeMillis () / 1000 ) );
220- payInfo .put ("nonceStr" , String . valueOf ( System . currentTimeMillis ()) );
222+ payInfo .put ("timeStamp" , timestamp );
223+ payInfo .put ("nonceStr" , nonceStr );
221224 } else if ("JSAPI" .equals (request .getTradeType ())) {
222225 payInfo .put ("appId" , unifiedOrderResult .getAppid ());
223226 // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
224- payInfo .put ("timeStamp" , String . valueOf ( System . currentTimeMillis () / 1000 ) );
225- payInfo .put ("nonceStr" , String . valueOf ( System . currentTimeMillis ()) );
227+ payInfo .put ("timeStamp" , timestamp );
228+ payInfo .put ("nonceStr" , nonceStr );
226229 payInfo .put ("package" , "prepay_id=" + prepayId );
227230 payInfo .put ("signType" , "MD5" );
228231 payInfo .put ("paySign" , SignUtils .createSign (payInfo , this .getConfig ().getMchKey ()));
229232 }
233+
230234 return payInfo ;
231235 }
232236
0 commit comments