微信公众号支付Java版本如何实现?
- 内容介绍
- 文章标签
- 相关推荐
本文共计633个文字,预计阅读时间需要3分钟。
java@RequestMapping(/toPay)public String toPay(HttpServletRequest request, HttpServletResponse response, Model model) { System.out.println(toPay success); try { String orderId=request.getParameter(orderId); System.out.println(orderId: + orderId); } catch (Exception e) { e.printStackTrace(); } return redirect:/success;}
@RequestMapping("/toPay")
public String toPay(HttpServletRequest request, HttpServletResponse response, Model model){
System.out.println("toPay success");
try {
String orderId = request.getParameter("orderId");
System.out.println("in toPay,orderId:" + orderId);
String totalFeeStr = request.getParameter("totalFee");
Float totalFee = 0.0f;
if(StringUtils.isNotBlank(totalFeeStr)){
totalFee = new Float(totalFeeStr);
}
//网页授权后获取传递的参数
//String userId = request.getParameter("userId");
String code = request.getParameter("code");
System.out.println("code:"+code);
//System.out.println("userId:"+userId);
//获取统一下单需要的openid
String openId ="";
String URL = "api.weixin.qq.com/sns/oauth2/access_token?appid="
+ WxPayConfig.appid + "&secret=" + WxPayConfig.appsecret + "&code=" + code + "&grant_type=authorization_code";
System.out.println("URL:"+URL);
JSONObject jsonObject = CommonUtil.api.mch.weixin.qq.com/pay/unifiedorder
//随机数
//String nonce_str = "1add1a30ac87aa2db72f57a2375d8fec";
String nonce_str = UUID.randomUUID().toString().replaceAll("-", "");
//商品描述
String body = orderId;
//商户订单号
String out_trade_no = orderId;
//订单生成的机器 IP
String spbill_create_ip = request.getRemoteAddr();
//总金额
//TODO
Integer total_fee = Math.round(totalFee*100);
//Integer total_fee = 1;
//商户号
//String mch_id = partner;
//子商户号 非必输
//String sub_mch_id="";
//设备号 非必输
//String device_info="";
//附加数据
//String attach = userId;
//总金额以分为单位,不带小数点
//int total_fee = intMoney;
//订 单 生 成 时 间 非必输
//String time_start ="";
//订单失效时间 非必输
//String time_expire = "";
//商品标记 非必输
//String goods_tag = "";
//非必输
//String product_id = "";
//这里notify_url是 支付完成后微信发给该链接信息,可以判断会员是否支付成功,改变订单状态等。
String notify_url = baseUrl + "/wx/notifyUrl.do";
SortedMap
本文共计633个文字,预计阅读时间需要3分钟。
java@RequestMapping(/toPay)public String toPay(HttpServletRequest request, HttpServletResponse response, Model model) { System.out.println(toPay success); try { String orderId=request.getParameter(orderId); System.out.println(orderId: + orderId); } catch (Exception e) { e.printStackTrace(); } return redirect:/success;}
@RequestMapping("/toPay")
public String toPay(HttpServletRequest request, HttpServletResponse response, Model model){
System.out.println("toPay success");
try {
String orderId = request.getParameter("orderId");
System.out.println("in toPay,orderId:" + orderId);
String totalFeeStr = request.getParameter("totalFee");
Float totalFee = 0.0f;
if(StringUtils.isNotBlank(totalFeeStr)){
totalFee = new Float(totalFeeStr);
}
//网页授权后获取传递的参数
//String userId = request.getParameter("userId");
String code = request.getParameter("code");
System.out.println("code:"+code);
//System.out.println("userId:"+userId);
//获取统一下单需要的openid
String openId ="";
String URL = "api.weixin.qq.com/sns/oauth2/access_token?appid="
+ WxPayConfig.appid + "&secret=" + WxPayConfig.appsecret + "&code=" + code + "&grant_type=authorization_code";
System.out.println("URL:"+URL);
JSONObject jsonObject = CommonUtil.api.mch.weixin.qq.com/pay/unifiedorder
//随机数
//String nonce_str = "1add1a30ac87aa2db72f57a2375d8fec";
String nonce_str = UUID.randomUUID().toString().replaceAll("-", "");
//商品描述
String body = orderId;
//商户订单号
String out_trade_no = orderId;
//订单生成的机器 IP
String spbill_create_ip = request.getRemoteAddr();
//总金额
//TODO
Integer total_fee = Math.round(totalFee*100);
//Integer total_fee = 1;
//商户号
//String mch_id = partner;
//子商户号 非必输
//String sub_mch_id="";
//设备号 非必输
//String device_info="";
//附加数据
//String attach = userId;
//总金额以分为单位,不带小数点
//int total_fee = intMoney;
//订 单 生 成 时 间 非必输
//String time_start ="";
//订单失效时间 非必输
//String time_expire = "";
//商品标记 非必输
//String goods_tag = "";
//非必输
//String product_id = "";
//这里notify_url是 支付完成后微信发给该链接信息,可以判断会员是否支付成功,改变订单状态等。
String notify_url = baseUrl + "/wx/notifyUrl.do";
SortedMap

