WxPayNativePay.php 1.37 KB
<?php

namespace WebPlugin\Pay\weixin\lib;

/**
 * 刷卡支付实现类
 *
 * @package WebPlugin\Pay\weixin\lib
 * @author Gtskk
 * @copyright 2016/3/21 21:01 Gtskk<iamgtskk@gmail.com>
 * @version: 0.0.1
 */
class WxPayNativePay
{
    /**
     *
     * 生成扫描支付URL,模式一
     * @param $productId
     * @return string
     * @throws WxPayException
     */
    public function GetPrePayUrl($productId)
    {
        $biz = new WxPayBizPayUrl();
        $biz->SetProduct_id($productId);
        $values = WxpayApi::bizpayurl($biz);
        $url = "weixin://wxpay/bizpayurl?" . $this->ToUrlParams($values);
        return $url;
    }

    /**
     *
     * 参数数组转换为url参数
     * @param array $urlObj
     * @return string
     */
    private function ToUrlParams($urlObj)
    {
        $buff = "";
        foreach ($urlObj as $k => $v)
        {
            $buff .= $k . "=" . $v . "&";
        }

        $buff = trim($buff, "&");
        return $buff;
    }

    /**
     *
     * 生成直接支付url,支付url有效期为2小时,模式二
     * @param UnifiedOrderInput $input
     * @return array
     */
    public function GetPayUrl($input)
    {
        if($input->GetTrade_type() == "NATIVE")
        {
            $result = WxPayApi::unifiedOrder($input);
            return $result;
        }
    }
}