PHP code example of pwf / paysdk
1. Go to this page and download the library: Download pwf/paysdk library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pwf / paysdk example snippets
wf\PaySDK\Base\PwfClient;
use Pwf\PaySDK\Base\Config;
//加载配置文件
$pwfClient = new PwfClient(getOptions());
//订单支付請求接口
$params = [
"trade_name" => "trade_name",
"fiat_currency" => "EUR",
"fiat_amount" => 0.01,
"out_trade_no" => "20200326235526001",
"subject" => "eur_pay",
"timestamp" => 1657895835,
"notify_url"=> "https://www.notify.com/notify", //此處的異步回調通知地址需與商戶中心配置的異步通知地址一致
"return_url" => "https://www.return.com/return",
"collection_model" => 1,
"merchant_no" => "<-- 請填寫您的商戶號,例如:2022......81170 -->",
];
$result = $pwfClient->execute("/api/v2/wallet/payAddress",$params);
if($result->isSuccess()){
if($result->verify()){
print_r($result->dataMap());
}else{
throw new \Exception("驗簽失敗,請檢查Pwf平台公鑰或商戶私鑰是否配置正確。");
}
}else{
throw new \Exception($result->ret() .":".$result->msg());
}
//异步回调通知處理示例
$json_string = '{"ret":1000,"msg":"\u8bf7\u6c42\u6210\u529f","data":"WDlwdnBoSkFDeS96bVdIYjg4WUNaaXVuV3NTQ......."}';
$result = $pwfClient->getApiResponse($json_string);
if($result->isSuccess()){
if($result->verify()){
print_r($result->dataMap());
}else{
throw new \Exception("驗簽失敗,請檢查Pwf平台公鑰或商戶私鑰是否配置正確。");
}
}
function getOptions()
{
$options = new Config();
$options->apiUrl = "<-- 請填寫平台分配的接口域名,例如:https://xxx.pwf.com/ -->";
$options->appToken = "<-- 請填寫您的appToken,例如:377b26eb8c25bd... -->";
//語系(參考文檔中最下方語系表,如:TC)
$options->lang = "TC";
$options->merchantPrivateCertPath = "<-- 請填寫您的應用私鑰路徑,例如:/foo/MyPrivateKey.pem -->";
$options->pwfPublicCertPath = "<-- 請填寫PWF平台公鑰證書文件路徑,例如:/foo/PwfPublicKey.pem -->";
return $options;
}