美文网首页PHP
微信支付api调用,请求数据,以便于前端拉起微信支付

微信支付api调用,请求数据,以便于前端拉起微信支付

作者: 剑指流云 | 来源:发表于2019-08-27 19:42 被阅读0次
    <?php
    include 'WxPay.Api.php';
    header("Access-Control-Allow-Origin: *");//跨域问题
    header("Content-type: text/html; charset=utf-8");//编码  
    $openid= $_GET['openid'];
    $total_fee = $_GET['total_fee'];
    $order_no = $_GET['dingdanhao'];
    $wxOrderData = new WxPayUnifiedOrder();
    $wxOrderData->SetTrade_type('JSAPI');
    $wxOrderData->SetOut_trade_no($order_no);
    $wxOrderData->SetTotal_fee($total_fee*100);
    $wxOrderData->SetBody('精品会');
    $wxOrderData->SetOpenid($openid);
    $wxOrderData->SetNotify_url('https://www.qdshengqian.com/fangxinshifu/notify.php');
    $wxOrder = WxPayApi::unifiedOrder($wxOrderData);
    $prepay_id = $wxOrder['prepay_id'];
    $jsApiPayData = new WxPayJsApiPay();
    $jsApiPayData->SetAppid('/* AppId */');
    $jsApiPayData->SetTimeStamp((string)time());
    $rand = md5(time().mt_rand(0,100));
    $jsApiPayData->SetNonceStr($rand);
    $jsApiPayData->SetPackage('prepay_id='.$prepay_id);
    $jsApiPayData->SetSignType('md5');
    $sign = $jsApiPayData->MakeSign();
    $rawValues = $jsApiPayData->GetValues();
    $rawValues['paySign']=$sign;
    echo json_encode($rawValues);
    ?>
    

    相关文章

      网友评论

        本文标题:微信支付api调用,请求数据,以便于前端拉起微信支付

        本文链接:https://www.haomeiwen.com/subject/dajyectx.html