payUtil.js 2.2 KB
import api from '../common/api.js';
import config from '../config';
function pay(data) {
    let orderCode = data.order_code;
    let param = {
        order_code: orderCode,
        payment_code: config.payment_code,
        openid: "4g0Q-X0ny9uLHASv",
    }
    api.get({data: param,url:"/payment/alipay_data"})
        .then(json=>{
            let data = json.data;
            if(data){
                let payParams = data.payParams;
                ttPayment(payParams);
            }
        
    })

}

//支付确认接口
function payConfirm(orderCode){
    if(!orderCode||orderCode==0){
        return
    }
    let param = {
        method:'app.SpaceOrders.payConfirm',
        order_code:orderCode,
        payment_id:45,
        // uid:"",
    }

    api.get({data: param})
        .then(json=>{
        
    })
}

function ttPayment(data){
    let paymentData = JSON.parse(data);
    let timestampStr = paymentData.timestamp+"";
    let total_amount = parseFloat(paymentData.total_amount);
    //头条需要该字段为String
    paymentData.timestamp = timestampStr;
    //头条需要该字段为数字
    paymentData.total_amount = total_amount;
    // let aliPayParam = paymentData.params;
    // let aliParam = JSON.parse(aliPayParam);
    // let testUrl = '_input_charset=\"utf-8\"&body=\"novel\"&it_b_pay=\"30m\"&notify_url=\"https://tp-pay-test.snssdk.com/callback/ali_pay\"&out_trade_no=\"201808211755020406852103\"&partner=\"2088801374045154\"&payment_type=\"1\"&seller_id=\"adsense@bytedance.com\"&service=\"mobile.securitypay.pay\"&subject=\"测试的商品\"&total_fee=\"0.01\"&sign=\"RGdwAoCy5DsjdFBdtrN9WzdYtyZGlUHn8dbAQVQsIPidLTR9s%2BCVtAj%2BtYzL8oAHP0IXJZw8U6EGlyA2MG2ZxhJRI1N1RhDMZOz56eAXO%2FITZYiGSB01hkhx9yhqmWAUJQfUMRHJZswS1DEpwam1JfaoahZ%2Bf%2FEE%2FkvG6ma67t4%3D\"&sign_type=\"RSA\"'
    // let testparam = {
    //     url: testUrl,
    // }
    // let url = JSON.stringify(testparam);
    tt.requestPayment({
        data:paymentData,
        success (res) {
            //支付成功以后跳转到支付成功页
            console.log("pay success"+res.errMsg);
        },
        fail (res) {
            console.log("pay fail"+res.errMsg);
        }
    })
}

module.exports = {
    aliPay: pay,
}