MUI 支付宝支付接入

沙箱测试地址:https://openhome.alipay.com/platform/appDaily.htm

1资源下载地址:https://docs.open.alipay.com/54/106370/  --下载手机网页支付demo .取出alipay-sdk-java20170307171631.jar 放入工程

app支付各接口说明:https://docs.open.alipay.com/api_1/alipay.trade.refund

2服务端配置:

########支付宝支付配置###########
#商户appid
zfb.APPID =
#私钥 pkcs8格式的
zfb.RSA_PRIVATE_KEY =
#服务器异步通知页面路径 需http://或者https://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问
zfb.notify_url =
#页面跳转同步通知页面路径 需http://或者https://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问 商户可以自定义同步跳转地址
zfb.return_url =
#请求网关地址
zfb.URL = https://openapi.alipaydev.com/gateway.do
#编码
zfb.CHARSET = UTF-8
#返回格式
zfb.FORMAT = json
#支付宝公钥
zfb.ALIPAY_PUBLIC_KEY =
#RSA2
zfb.SIGNTYPE = RSA2

########支付宝支付配置###########

3服务端获取订单: 参考地址:https://docs.open.alipay.com/54/106370/    其他退款,查看,下载对账单等参考地址:https://docs.open.alipay.com/204/105297/

 String out_trade_no = request.getParameter("orderId");
String subject = request.getParameter("orderName");
String total_amount=request.getParameter("ordreMoney");
System.out.println("订单号ID:"+out_trade_no);

/* // 商品描述,可空
String body = "没有描述";
// 超时时间 可空
String timeout_express="2000m";
// 销售产品码 必填
String product_code="QUICK_WAP_PAY";*/


System.out.println(zfb.toString());
AlipayClient alipayClient = new DefaultAlipayClient(zfb.getURL(),
zfb.getAPPID(),
zfb.getRSA_PRIVATE_KEY(),
zfb.getFORMAT(),
zfb.getCHARSET(),
zfb.getALIPAY_PUBLIC_KEY(),
zfb.getSIGNTYPE());
AlipayTradeAppPayRequest alipay_request = new AlipayTradeAppPayRequest();
//SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
model.setBody("我是测试数据");
model.setSubject("App支付测试Java");
model.setOutTradeNo("6786785675674564");
model.setTimeoutExpress("30m");
model.setTotalAmount("0.01");
model.setProductCode("QUICK_MSECURITY_PAY");
alipay_request.setBizModel(model);
alipay_request.setNotifyUrl("商户外网可以访问的异步地址");
try {
//这里和普通的接口调用不同,使用的是sdkExecute
AlipayTradeAppPayResponse response = alipayClient.sdkExecute(alipay_request);
String order = response.getBody();
System.out.println("订单");
System.out.println(order);//就是orderString 可以直接给客户端请求,无需再做处理。
return new ReturnVO(order);
} catch (AlipayApiException e) {
e.printStackTrace();
}
return new ReturnVO(false);
4 mui端调用支付宝支付sdk配置及代码 参考地址:http://ask.dcloud.net.cn/article/71
配置:

manifes.json增加

"permissions": >>

    "Payment":{

      "description": "支付宝支付"

    },

"plus">>"distribute">>

     {"plugins":{"payment":{"alipay":{"description":"支付宝支付","scheme":""}}},

 

代码:

mui.init({  

        swipeBack:true //启用右滑关闭功能  

    }); 

   

   

    //获取支付通道

    var channel=null;

function plusReady(){

    // 获取支付通道

    plus.payment.getChannels(function(channels){

        channel=channels[0];

    },function(e){

        alert("获取支付通道失败:"+e.message);

    });

}

document.addEventListener('plusready',plusReady,false);

 

var ALIPAYSERVER='https://openapi.alipaydev.com/gateway.do?';  

    var WXPAYSERVER='http://demo.dcloud.net.cn/helloh5/payment/wxpay.php?total='; 

    var PAYSERVER='';

//发起支付请求

function pay(id){

    // 从服务器请求支付订单

   

    if(id=='alipay'){

        PAYSERVER=ALIPAYSERVER;

    }else if(id=='wxpay'){

        PAYSERVER=WXPAYSERVER;

    }else{

        plus.nativeUI.alert("不支持此支付通道!",null,"捐赠");

        return;

    }

    var xhr=new XMLHttpRequest();

    xhr.onreadystatechange=function(){

        switch(xhr.readyState){

            case 4:

            if(xhr.status==200){

                plus.payment.request(channel,xhr.responseText,function(result){

                    plus.nativeUI.alert("支付成功!",function(){

                        back();

                    });

                },function(error){

                    plus.nativeUI.alert("支付失败:" + error.code);

                });

            }else{

                alert("获取订单信息失败!");

            }

            break;

            default:

            break;

        }

    }

    xhr.open('GET',PAYSERVER);

    xhr.send();

}

 

//添加列表项的点击事件

mui('.mui-input-group').on('tap',"#pay_sub", function(e) {

console.log(bathpath+'/zfb/pay');

$.getJSON({

        url:bathpath+'/zfb/pay',

        type: 'post',

        data:{

    orderId:'999999999',

orderName:'测试商品1',

ordreMoney:'0.01'

}

    }).done(function (result) {

console.log(result.content);

ALIPAYSERVER=ALIPAYSERVER+result.content;

pay('alipay');

    }).fail(function (e) {

        console.error(e.statusText)

    }).always(function () {

   

    });

});

posted @ 2018-01-08 18:32  itvita  阅读(5561)  评论(0编辑  收藏  举报