即时到帐支付丨API支付丨接口申请提供商丨BC-Zpay平台网

抖音小程序调起支付宝支付API接口

admin
内部订单号生成后,下一步调支付宝支付。
 
下面php代码:
 
$paramList= array('out_trade_no' => $outTradeNo, 'total_amount' => $orderInfo['money'], 'subject' =>$orderName, 'body' => $bodyName . ':0:TTAPP');
$sec = pdo_fetch('select * from ' . tablename('ewei_shop_sysset') . ' where uniacid=:uniacid limit 1', array(':uniacid' => 59));
$sec = iunserializer($sec['sec']);
$alipay_config = $sec['app_alipay'];
if (!empty($alipay_config)) {
    $reNews = $this->alipay_build($paramList, $alipay_config);
    $alipay = array('success' => true, 'payinfo' => $reNews);//生成调起支付宝url
}
$params=array();
$params['app_id']=$this->appId;
$params['sign_type']='MD5';
$params['out_order_no']=$out_order_no;//抖音小程序内部生成的订单号
$params['merchant_id']=$this->merchant_id;
$params['timestamp']=strval(time());
$params['product_code']='pay';
$params['payment_type']='direct';
$params['total_amount']=$totalFee*100;
$params['trade_type']='H5';
$params['uid']=$openid;
$params['version']='2.0';
$params['currency']='CNY';
$params['subject']=$orderName;
$params['body']=$bodyName;
$params['trade_time']=strval($requestConfigs['trade_time']);
$params['valid_time']='300';
$params['notify_url']=$this->root .'payment/alipay/notify.php';
$params['alipay_url']=!empty($alipay['success'])?$alipay['payinfo']:'';
$params['wx_type']='';
$params['wx_url']='';
$oplist=$this->getSignContent($params , $dataList['charset'] ,$this->Key);
$params['sign']=md5($oplist);
return  $params;//返回前端数据
 public function alipay_build($params, $config = array()){
        global $_W;
        $arr = array('app_id' => $config['appid'], 'method' => 'alipay.trade.app.pay', 'format' => 'JSON', 'charset' => 'utf-8', 'sign_type' => 'RSA2', 'timestamp' => date('Y-m-d H:i:s', time()), 'version' => '1.0', 'notify_url' => $_W['siteroot'] . 'payment/alipay/notify.php', 'biz_content' => json_encode(array('timeout_express' => '90m', 'product_code' => 'QUICK_MSECURITY_PAY', 'total_amount' => $params['total_amount'], 'subject' => $params['subject'], 'body' => $params['body'], 'out_trade_no' => $params['out_trade_no'])));
        ksort($arr);
        $string1 = '';
        foreach ($arr as $key => $v )
        {
            if (empty($v))
            {
                continue;
            }
            $string1 .= $key . '=' . $v . '&';
        }
        $string1 = rtrim($string1, '&');
        $pkeyid = openssl_pkey_get_private($this->chackKey($config['private_key_rsa2'], false));
        if ($pkeyid === false)
        {
            return error(-1, '提供的私钥格式不对');
        }
        $signature = '';
        openssl_sign($string1, $signature, $pkeyid, OPENSSL_ALGO_SHA256);
        openssl_free_key($pkeyid);
        $signature = base64_encode($signature);
        $arr['sign'] = $signature;
        return http_build_query($arr);
    }
 
    public function chackKey($key, $public = true)
    {
        if (empty($key)) {
            return $key;
        }
 
        if ($public) {
            if (strexists($key, '-----BEGIN PUBLIC KEY-----')) {
                $key = str_replace(array('-----BEGIN PUBLIC KEY-----', '-----END PUBLIC KEY-----'), '', $key);
            }
 
            $head_end = '-----BEGIN PUBLIC KEY-----
{key}
-----END PUBLIC KEY-----';
        }
        else {
            if (strexists($key, '-----BEGIN RSA PRIVATE KEY-----')) {
                $key = str_replace(array('-----BEGIN RSA PRIVATE KEY-----', '-----END RSA PRIVATE KEY-----'), '', $key);
            }
 
            $head_end = '-----BEGIN RSA PRIVATE KEY-----
{key}
-----END RSA PRIVATE KEY-----';
        }
 
        $key = str_replace(array('
', '
', '
'), '', trim($key));
        $key = wordwrap($key, 64, '
', true);
        return str_replace('{key}', $key, $head_end);
    }
HTML代码:
 
tt.pay({
 
orderInfo: e.data,
 
service: 4,
 
_debug:1,
 
getOrderStatus(res) {
 
console.log(res)
 
},
 
success(res) {
 
console.log('成功',res)
 
if (res.code == 0) {
 
// 支付成功处理逻辑,只有res.code=0时,才表示支付成功
 
// 但是最终状态要以商户后端结果为准
 
}
 
},
 
fail(res) {
 
console.log('失败',res)
 
// 调起收银台失败处理逻辑
 
}
 
 
 
这是我返回前端数据:

上一篇:抖音上推荐付款多久运作

下一篇:没有了