支付宝扫码支付示例源码
支付宝扫码付,相对来说根据开发文档开发的话,基本上可以一遍过的.直接上代码.
controller:
@RequestMapping(value = {"/api/alijspay"})
@RestController
@Slf4j
@Api(value = "alipay扫码支付相关",tags = "alipay扫码支付相关")
public class AliJSPayController extends BaseController {
@Autowired
private lAliPayService aliPayService;
@PostMapping("/payRequest")
@ApiOperation("统一下单alipay支付.")
public Result payRequest(HttpServletResponse responses, @RequestBody MallOrderJSPayDto mallOrderJSPayDto) throws Exception {
log.info("ali 支付:{}",mallOrderJSPayDto);
try {
Map<String,String> map = aliPayService.jsPayRequest(responses,mallOrderJSPayDto);
return super.success(map);
} catch (Exception e) {
log.info("订单ali支付异常:{}",e);
return super.error("订单数据异常!");
}
}
@PostMapping(value = "/aliPayOrderCallBack")
@ApiOperation("alipay支付回调")
public Map<String, String> aliPayOrderCallBack(HttpServletRequest request){
Map<String, String> map = new HashMap<String, String>();
try {
AliPayVO aliPayVo = aliPayService.aliJsPayCallBack(request);
aliPayService.aliJsPayOrderCallBack(aliPayVo);
map.put("msg", "SUCCESS");
} catch (Exception e) {
e.printStackTrace();
log.error("aliPayOrderCallBack Error.",e);
}
return map;
}
@PostMapping(value = "/getAliJspayStaus")
@ApiOperation("alipay扫码付状态查询")
public Result getAlijspayStaus(@RequestParam("orderId")String orderId){
Map<String, Object> map = new HashMap<String, Object>();
try {
map = aliPayService.getAlijspayStaus(orderId);
return super.success(map);
} catch (Exception e) {
e.printStackTrace();
log.error("aliPayOrderCallBack Error.",e);
}
return super.error();
}
}
service:
public interface FriendsMallAliPayService {
//支付宝扫码支付
public Map<String,String> jsPayRequest(HttpServletResponse responses, MallOrderJSPayDto mallOrderPayDto) throws Exception;
//支付宝扫码付订单状态查询
public Map<String, Object> getAlijspayStaus(String orderId) throws Exception;
//支付宝扫码付支付宝回调
public AliPayVO aliJsPayCallBack(HttpServletRequest request) throws Exception;
//支付宝扫码付订单支付回调业务处理
public void aliJsPayOrderCallBack(AliPayVO aliPayVo) throws Exception;
}
Impl:
@Override
public Map<String,String> jsPayRequest(HttpServletResponse responses, MallOrderJSPayDto mallOrderPayDto) throws Exception {
//TODO 要查库.获取配置-扫码付单独一套支付库表
AlipayConfig alipayConfig = new AlipayConfig();
alipayConfig.setUrl(Consts.ALIPAY_REQUEST_URI);
alipayConfig.setAppId("");//appId
alipayConfig.setRsaPrivateKey("");//私钥
alipayConfig.setAlipayPublicKey("");//公钥
alipayConfig.setCharset(Consts.ALIPAY_CHARSET);//编码格式