支付宝扫码支付示例源码

支付宝扫码支付示例源码

支付宝扫码付,相对来说根据开发文档开发的话,基本上可以一遍过的.直接上代码.

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);//编码格式
  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值