<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                > 快速對接支付寶接口,首先您需要創建一個控制器,名稱叫`Alipay.class.php`,然后保存下面的代碼到文件中,命名空間需要修改成您當前實例的命名空間: ~~~ <?php namespace App\home; class Alipay { protected $appId; protected $returnUrl; protected $notifyUrl; protected $charset; //私鑰值 protected $rsaPrivateKey; protected $totalFee; protected $outTradeNo; protected $orderName; public function __construct() { $this->charset = 'utf8'; } public function setAppid($appid) { $this->appId = $appid; } public function setReturnUrl($returnUrl) { $this->returnUrl = $returnUrl; } public function setNotifyUrl($notifyUrl) { $this->notifyUrl = $notifyUrl; } public function setRsaPrivateKey($saPrivateKey) { $this->rsaPrivateKey = $saPrivateKey; } public function setTotalFee($payAmount) { $this->totalFee = $payAmount; } public function setOutTradeNo($outTradeNo) { $this->outTradeNo = $outTradeNo; } public function setOrderName($orderName) { $this->orderName = $orderName; } /** * 發起訂單 * @return array */ public function doPay() { //請求參數 $requestConfigs = array( 'out_trade_no' => $this->outTradeNo, 'product_code' => 'FAST_INSTANT_TRADE_PAY', 'total_amount' => $this->totalFee, //單位 元 'subject' => $this->orderName, //訂單標題 ); $commonConfigs = array( //公共參數 'app_id' => $this->appId, 'method' => 'alipay.trade.page.pay', //接口名稱 'format' => 'JSON', 'return_url' => $this->returnUrl, 'charset' => $this->charset, 'sign_type' => 'RSA2', 'timestamp' => date('Y-m-d H:i:s'), 'version' => '1.0', 'notify_url' => $this->notifyUrl, 'biz_content' => json_encode($requestConfigs), ); $commonConfigs["sign"] = $this->generateSign($commonConfigs, $commonConfigs['sign_type']); return $this->buildRequestForm($commonConfigs); } /** * 建立請求,以表單HTML形式構造(默認) * @param $para_temp 請求參數數組 * @return 提交表單HTML文本 */ protected function buildRequestForm($para_temp) { $sHtml = "正在跳轉至支付頁面...<form id='alipaysubmit' name='alipaysubmit' action='https://openapi.alipay.com/gateway.do?charset=" . $this->charset . "' method='POST'>"; foreach ($para_temp as $key => $val) { if (false === $this->checkEmpty($val)) { $val = str_replace("'", "&apos;", $val); $sHtml .= "<input type='hidden' name='" . $key . "' value='" . $val . "'/>"; } } //submit按鈕控件請不要含有name屬性 $sHtml = $sHtml . "<input type='submit' value='ok' style='display:none;''></form>"; $sHtml = $sHtml . "<script>document.forms['alipaysubmit'].submit();</script>"; return $sHtml; } public function generateSign($params, $signType = "RSA") { return $this->sign($this->getSignContent($params), $signType); } protected function sign($data, $signType = "RSA") { $priKey = $this->rsaPrivateKey; $res = "-----BEGIN RSA PRIVATE KEY-----\n" . wordwrap($priKey, 64, "\n", true) . "\n-----END RSA PRIVATE KEY-----"; ($res) or die('您使用的私鑰格式錯誤,請檢查RSA私鑰配置'); if ("RSA2" == $signType) { openssl_sign($data, $sign, $res, version_compare(PHP_VERSION, '5.4.0', '<') ? SHA256 : OPENSSL_ALGO_SHA256); //OPENSSL_ALGO_SHA256是php5.4.8以上版本才支持 } else { openssl_sign($data, $sign, $res); } $sign = base64_encode($sign); return $sign; } /** * 校驗$value是否非空 * if not set ,return true; * if is null , return true; **/ protected function checkEmpty($value) { if (!isset($value)) return true; if ($value === null) return true; if (trim($value) === "") return true; return false; } public function getSignContent($params) { ksort($params); $stringToBeSigned = ""; $i = 0; foreach ($params as $k => $v) { if (false === $this->checkEmpty($v) && "@" != substr($v, 0, 1)) { // 轉換成目標字符集 $v = $this->characet($v, $this->charset); if ($i == 0) { $stringToBeSigned .= "$k" . "=" . "$v"; } else { $stringToBeSigned .= "&" . "$k" . "=" . "$v"; } $i++; } } unset ($k, $v); return $stringToBeSigned; } /** * 轉換字符集編碼 * @param $data * @param $targetCharset * @return string */ function characet($data, $targetCharset) { if (!empty($data)) { $fileType = $this->charset; if (strcasecmp($fileType, $targetCharset) != 0) { $data = mb_convert_encoding($data, $targetCharset, $fileType); //$data = iconv($fileType, $targetCharset.'//IGNORE', $data); } } return $data; } } ~~~ ### 使用: > 然后在把下面的方法粘貼到您的另一個控制器里面,在需要調用的地方直接通過$this->alipays('appid','跳轉url','通知url','訂單號','支付金額','RSA2','私鑰')`,注意使用要修改好參數即可 ~~~ /** * 支付寶付款 * @param $appid * @param $returnUrl string 支付成功跳轉的URL * @param $notifyUrl string 支付成功異步通知的URL * @param $outTradeNo string 訂單號 * @param $payAmount string 支付金額 * @param $signType string 簽名類型 * @param $rsaPrivateKey string 支付寶私鑰 */ public function alipays($appid, $returnUrl, $notifyUrl, $outTradeNo, $payAmount, $signType='RSA2', $rsaPrivateKey) { header('Content-type:text/html; Charset=utf-8'); $orderName = '商品購買訂單付款'; //訂單標題 /*** 配置結束 ***/ $aliPay = new Alipay(); $aliPay->setAppid($appid); $aliPay->setReturnUrl($returnUrl); $aliPay->setNotifyUrl($notifyUrl); $aliPay->setRsaPrivateKey($rsaPrivateKey); $aliPay->setTotalFee($payAmount); $aliPay->setOutTradeNo($outTradeNo); $aliPay->setOrderName($orderName); $sHtml = $aliPay->doPay(); echo $sHtml; } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看