日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

html wap php,wap.php

發(fā)布時(shí)間:2024/9/27 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 html wap php,wap.php 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

header('Content-type:text/html; Charset=utf-8');

/*** 請(qǐng)?zhí)顚懸韵屡渲眯畔?***/

$appid = 'xxxxx'; //https://open.alipay.com 賬戶中心->密鑰管理->開放平臺(tái)密鑰,填寫添加了電腦網(wǎng)站支付的應(yīng)用的APPID

$returnUrl = 'http://www.xxx.com/alipay/return.php'; //付款成功后的同步回調(diào)地址

$notifyUrl = 'http://www.xxx.com/alipay/notify.php'; //付款成功后的異步回調(diào)地址

$outTradeNo = uniqid(); //你自己的商品訂單號(hào)

$payAmount = 0.01; //付款金額,單位:元

$orderName = '支付測(cè)試'; //訂單標(biāo)題

$signType = 'RSA2';//簽名算法類型,支持RSA2和RSA,推薦使用RSA2

$rsaPrivateKey='xxxxx';//商戶私鑰,填寫對(duì)應(yīng)簽名算法類型的私鑰,如何生成密鑰參考:https://docs.open.alipay.com/291/105971和https://docs.open.alipay.com/200/105310

/*** 配置結(jié)束 ***/

$aliPay = new AlipayService();

$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;

class AlipayService

{

protected $appId;

protected $charset;

protected $returnUrl;

protected $notifyUrl;

//私鑰值

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($rsaPrivateKey)

{

$this->rsaPrivateKey = $rsaPrivateKey;

}

public function setTotalFee($payAmount)

{

$this->totalFee = $payAmount;

}

public function setOutTradeNo($outTradeNo)

{

$this->outTradeNo = $outTradeNo;

}

public function setOrderName($orderName)

{

$this->orderName = $orderName;

}

/**

* 發(fā)起訂單

* @return array

*/

public function doPay()

{

//請(qǐng)求參數(shù)

$requestConfigs = array(

'out_trade_no'=>$this->outTradeNo,

'product_code'=>'QUICK_WAP_WAY',

'total_amount'=>$this->totalFee, //單位 元

'subject'=>$this->orderName, //訂單標(biāo)題

);

$commonConfigs = array(

//公共參數(shù)

'app_id' => $this->appId,

'method' => 'alipay.trade.wap.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);

}

/**

* 建立請(qǐng)求,以表單HTML形式構(gòu)造(默認(rèn))

* @param $para_temp 請(qǐng)求參數(shù)數(shù)組

* @return 提交表單HTML文本

*/

protected function buildRequestForm($para_temp) {

$sHtml = "

";

while (list ($key, $val) = each ($para_temp)) {

if (false === $this->checkEmpty($val)) {

$val = str_replace("'","'",$val);

$sHtml.= "";

}

}

//submit按鈕控件請(qǐng)不要含有name屬性

$sHtml = $sHtml."

";

$sHtml = $sHtml."";

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('您使用的私鑰格式錯(cuò)誤,請(qǐng)檢查RSA私鑰配置');

if ("RSA2" == $signType) {

openssl_sign($data, $sign, $res, version_compare(PHP_VERSION,'5.4.0', '

} else {

openssl_sign($data, $sign, $res);

}

$sign = base64_encode($sign);

return $sign;

}

/**

* 校驗(yàn)$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)) {

// 轉(zhuǎn)換成目標(biāo)字符集

$v = $this->characet($v, $this->charset);

if ($i == 0) {

$stringToBeSigned .= "$k" . "=" . "$v";

} else {

$stringToBeSigned .= "&" . "$k" . "=" . "$v";

}

$i++;

}

}

unset ($k, $v);

return $stringToBeSigned;

}

/**

* 轉(zhuǎn)換字符集編碼

* @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;

}

}

一鍵復(fù)制

編輯

Web IDE

原始數(shù)據(jù)

按行查看

歷史

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的html wap php,wap.php的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。