要根据自己实际业务需求进行更改,不可照搬
mespace App\Controller;
require_once('ThinkPHP/Library/Vendor/Ping/init.php');
/**
* P++支付接口类
* Class PingController
* @package App\Controller
*/
class PingController extends AppController
{
private $appkey;
private $appid;
public function __construct()
{
parent::__construct();
$this->appkey = C('PING_APP_KEY');
$this->appid = C('PING_APP_ID');
}
public function paymentMethod(){
$input_data['channel'] = I('channel');
$input_data['amount'] = I('amount');
\Pingpp\Pingpp::setApiKey($this->appkey);// 设置 API Key
\Pingpp\Pingpp::setPrivateKeyPath(THINK_PATH . 'Library/Vendor/Ping/data/rsa_private_key.pem');// 设置私钥
$channel = strtolower($input_data['channel']);//支付渠道
$extra = array();
switch ($channel) {
case 'alipay':
$extra = array();
break;
case 'wx':
$extra = array();
break;
}
try {
$ch = \Pingpp\Charge::create(
array(
//请求参数字段规则,请参考 API 文档:https://www.pingxx.com/api#api-c-new
'subject' => "",//商品的标题,该参数最长为 32 个 Unicode 字符,银联全渠道( upacp / upacp_wap )限制在 32 个字节。
'body' => "",//商品的描述信息,该参数最长为 128 个 Unicode 字符,yeepay_wap 对于该参数长度限制为 100 个 Unicode 字符。
'amount' => "",//订单总金额, 人民币单位:分(如订单总金额为 1 元,此处请填 100)
'order_no' => "",// 推荐使用 8-20 位,要求数字或字母,不允许其他字符
'currency' => 'cny',//三位 ISO 货币代码,目前仅支持人民币 cny 。
'extra' => $extra,//特定渠道发起交易时需要的额外参数,以及部分渠道支付成功返回的额外参数,详细参考 支付渠道 extra 参数说明
'channel' => $channel,// 支付使用的第三方支付渠道取值,请参考:https://www.pingxx.com/api#api-c-new
'client_ip' => $_SERVER['REMOTE_ADDR'],// 发起支付请求客户端的 IP 地址,格式为 IPV4,如: 127.0.0.1
'app' => array('id' => $this->appid),//支付使用的 app 对象的 id , expandable 可展开,查看 如何获取App ID 。
'metadata' =>""
)
);
$data['charges'] = (string)$ch;
返回客户端支付凭证 $data
} catch (\Pingpp\Error\Base $e) {
// 捕获报错信息
if ($e->getHttpStatus() != null) {
header('Status: ' . $e->getHttpStatus());
echo $e->getHttpBody();
} else {
echo $e->getMessage();
}
}
}
ping++支付
最新推荐文章于 2022-04-21 13:23:45 发布