近来对于支付来点兴趣,所有写了一个微信H5的demo来给大家参考一下。
@RequestMapping(value ="/H5",method = {RequestMethod.POST,RequestMethod.GET})
public String H5(){
return "text_jsp/h5";//
}
/**
* 微信H5 支付--------------------好使
* 注意:必须再web页面中发起支付且域名已添加到开发配置中
* @throws DocumentException
* @throws IOException
*/
@RequestMapping(value ="/H5Pay",method = {RequestMethod.POST,RequestMethod.GET})
public void H5Pay(HttpServletRequest request,HttpServletResponse response,String ip) throws IOException, DocumentException{
System.out.println("微信H5支付开始了=====================================");
String value = String.valueOf(System.currentTimeMillis());
SortedMap<String, String> packageParams = new TreeMap<String, String>();
String nonce_str = UUID.randomUUID().toString().replaceAll("-", "");
String spbill_create_ip = request.getRemoteAddr();
String khdIP = getIpAddr(request);
System.out.println("java获取真实客户端IP====================================="+khdIP);
//String nonce_str = String.valueOf(System.currentTimeMillis());
packageParams.put("appid", appID);
packageParams.put("body", "龙图腾");
packageParams.put("mch_id", mchID);
packageParams.put("nonce_str", nonce_str);
packageParams.put("out_trade_no", value);
packageParams.put("total_fee", "1");
packageParams.put("spbill_create_ip",khdIP);
packageParams.put("notify_url", h5_notify_url);
packageParams.put("trade_type", "MWEB&#