码迷,mamicode.com
首页 > 编程语言 > 详细

java更新支付状态以及原路径退款

时间:2017-05-12 20:21:14      阅读:536      评论:0      收藏:0      [点我收藏+]

标签:trade   aos   err   mon   private   app   als   tps   try   

java(支付宝)跟新支付状态

————————————————————————————————————————

 ————Controller层————

public class ZhiFuBaoController {
@Resource
private ZhiFuBaoService zhiFuBao;

@RequestMapping("addZhiFuBao")
@ResponseBody

// model 接收支付宝传过来的数据
public String addZhiFu(ZhiFuBaoDTO model) {
return zhiFuBao.addZhiFuBao(model);
}

}

————业务逻辑层————

public String addZhiFuBao(ZhiFuBaoDTO model) {
String pkid = model.getOut_trade_no(); // 商家单号
String trade_no = model.getTrade_no();// 支付宝单号
if ("TRADE_FINISHED".equalsIgnoreCase(model.getTrade_status())
|| "TRADE_SUCCESS".equalsIgnoreCase(model.getTrade_status())) {
DicDingDanDTO pk = dindan.getDingDan(pkid);//通过商户订单号获取相应的数据

double payMoney = Double.parseDouble(model.getTotal_fee());
double money = pk.getMoney();
double deposit = money;
if (payMoney == money) {


   ————业务逻辑————

}

return "success";
}

return "error";
}
}

java 原路径退款

——————————————————————————————————————————————————————————————————————

————Controller层————

public class TuiKuanController {
@Resource
private TuiKuanService tuiKuanService;
@RequestMapping("tuiKuan")
@ResponseBody
public ResultData getTuiKuan(String pkphone){
return tuiKuanService.getTuiKuan(pkphone);
}

}

 

————业务逻辑层————

public ResultData getTuiKuan(String pkphone) {
ResultData result = new ResultData();
if (pkphone == null) {
result.setMsg("参数有空");
result.setStatus(1);
return result;
}
DicDingDanDTO tuikuan = tuiKuanDao.getTuiKuan(pkphone);
String pkid = tuikuan.getPkid();// 订单号
String trade_no = tuikuan.getTradeNo();// 支付宝单号
Double money = tuikuan.getMoney();// 退款金额

//app_id,private_key,alipay_public_key这几个参数需要用你自己的

AlipayClient alipayClient = new DefaultAlipayClient( 
"https://openapi.alipay.com/gateway.do", app_id, private_key,
"json", "GBK", alipay_public_key, "RSA");
AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
AlipayTradeRefundModel model = new AlipayTradeRefundModel();
model.setOutTradeNo(pkid);
model.setTradeNo(trade_no);
model.setRefundAmount(money);
request.setBizModel(model);
AlipayTradeRefundResponse response = null;
try {
response = alipayClient.execute(request);
System.out.println(response.getBody());
System.out.println(response);
} catch (AlipayApiException e) {
e.printStackTrace();
}
if (response.isSuccess()) {
System.out.println("调用成功");
} else {
System.out.println("调用失败");
return result;
}
————————

*****这里需要写你需要的一些业务逻辑

————————
result.setMsg("退款成功!预计3-7个工作日到帐!");
result.setStatus(0);
return result;
}
}

 

java更新支付状态以及原路径退款

标签:trade   aos   err   mon   private   app   als   tps   try   

原文地址:http://www.cnblogs.com/yucidada/p/6846857.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!