thinkphp框架中引出ping++支付server SDK
thinkphp框架中引入ping++支付server SDK
ping++支付平台整合了支付宝,微信支付,百度钱包,银联支付等主流支付方式。而且其开发文档,也很容易理解和上手,所以想写篇博客,记录下来(thinkphp)服务器端使用其SDK的步骤【test模式下】。
开始之前 最好先看一看官方文档对于支付过程的解释:
第一步:去www.pingxx.com新注册一个账号。注册完成进入个人中心后,你将会得到一些参数:
①Test Secret Key:(该参数在server端配置,用于和客户端的Test Publishable Key配合使用)
②ping++公钥:(支付完成后,平台往server端返回webhooks,此参数用于验证交易安全性)
③Test Publishable Key:(该参数用于客户端,与上面server端的的Test Serect Key配合使用)
④商户公钥:(用于server端和平台交易时,RSA签名的验证),至于如何产生商户公钥对,根据图中蓝色字的引导,很容易就完成了,此处不再赘述。产生了公钥对之后,把公钥填写在下图中的textarea中,私钥留着先,后面有用。
第二步:下载官方的server端SDK,PHP的下载链接是https://github.com/PingPlusPlus/pingpp-php
下载好了之后,加压出来,放在thinkphp第三方库扩展目录里面:
如左图所示,lib文件夹,init.php,还有第一步④产生的公钥对中的
私钥放进去。至于data文件夹里的文件,是使用HTTPS时用的安全证书,暂时也拿过来。
第三步:在代码中使用上面的参数,看看引入是否成功:(示例代码如下)
public function index(){ $api_key = '请填写自己的Test Serect Key'; //API-KEY,注册ping++时自动生成 $app_id = '请填写自己的APP的ID'; //APP_ID,注册时自动生成 Vendor('pingpp.init'); //引入类库初始化文件 //以支付宝,支付10块钱。注意amount为1000,单位是”分钱“ $input_data = array('channel'=>'alipay', 'amount'=>1000); //$input_data应该是你从APP客户端收到的json数据(根据业务可以在服务器端定义),需json_decode if (empty($input_data['channel']) || empty($input_data['amount'])) { echo 'channel or amount is empty'; //检验支付参数 exit(); } $channel = strtolower($input_data['channel']); //支付渠道:支付宝 $amount = $input_data['amount']; //支付金额10块钱 $orderNo = substr(md5(time()), 0, 12); //订单号,必须唯一。根据支付渠道不同,长度要求也不一样,请查看文档https://www.pingxx.com/api#api-c-new \Pingpp\Pingpp::setPrivateKeyPath(VENDOR_PATH . '/pingpp/rsa_private_key.pem'); //引入你的签名私钥 //$extra用于设置支付渠道所需的额外参数,额外参数多数是可选,请根据需求来决定。详情看参考文档 // $extra = array( // 'success_url' => 'http://example.com/success', // 'cancel_url' => 'http://example.com/cancel' // ); \Pingpp\Pingpp::setApiKey($api_key); //设置API-KEY try { $ch = \Pingpp\Charge::create( //create方法表示发送支付请求到ping++平台,$ch表示请求成功时返回的charge对象(json格式),服务器端如果发起请求成功,此时只需要把charge对象传递给APP客户端,交给客户端处理 array( 'subject' => 'Your Subject', //关于这些参数的意义,请参考文档https://www.pingxx.com/api#api-c-new 'body' => 'Your Body', 'amount' => $amount, 'order_no' => $orderNo, 'currency' => 'cny', // 'extra' => $extra, 'channel' => $channel, 'client_ip' => $_SERVER['REMOTE_ADDR'], 'app' => array('id' => $app_id) ) ); echo $ch; } catch (\Pingpp\Error\Base $e) { //如果发起支付请求失败,则抛出异常 // 捕获报错信息 if ($e->getHttpStatus() != NULL) { header('Status: ' . $e->getHttpStatus()); echo $e->getHttpBody(); } else { echo $e->getMessage(); } } //代码到此处,如果你向ping++平台请求支付成功,并且把charge对象传递给了客户端,那么接下来客户端如果成功完成了支付,那么 //平台将会请求你填写的Webhooks回调url,在该url里,接收 Webhooks 通知,根据数据的结果做出逻辑判断:如果支付成功....,如果支付失败...
如果此时,能在浏览器返回一串json数据,那么你的初步调试就通过了。
第四步:填写你的webhook的回调地址。如果客户端发起的支付,已经完成交易,那么交易成功的json消息,会
返回到该回调地址,你根据json消息,对自己的数据库和业务作出相应的回应或者抛出支付错误信息。webhook的填
写,请到个人中心去填写,很容易的,不再赘述。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



WindowsServerBackup is a function that comes with the WindowsServer operating system, designed to help users protect important data and system configurations, and provide complete backup and recovery solutions for small, medium and enterprise-level enterprises. Only users running Server2022 and higher can use this feature. In this article, we will explain how to install, uninstall or reset WindowsServerBackup. How to Reset Windows Server Backup If you are experiencing problems with your server backup, the backup is taking too long, or you are unable to access stored files, then you may consider resetting your Windows Server backup settings. To reset Windows

On the occasion of releasing the build 26040 version of Windows Server, Microsoft announced the official name of the product: Windows Server 2025. Also launched is the Windows11WindowsInsiderCanaryChannel version build26040. Some friends may still remember that many years ago someone successfully converted Windows NT from workstation mode to server mode, showing the commonalities between various versions of Microsoft operating systems. Although there are clear differences between Microsoft's current version of the server operating system and Windows 11, those who pay attention to the details may be curious: why Windows Server updated the brand,

How to modify the default name of nginx, you can disguise it a little, or you can install Tip: Generally, modifications are made before nginx is compiled. After modification, the code needs to be recompiled as follows: scr/core/nginx.conf#definenginx_version"1.4.7"#definenginx_ver"nginx/"n

While Microsoft released the Win11 preview update for the desktop, today it also released the Windows Server Long Term Service Channel (LTSC) preview Build 25335. As usual, Microsoft did not publish a complete change log, or even provide a corresponding blog post. Microsoft has adjusted the Windows Server preview version update log to make it the same as the Canary channel version. If no new content is introduced, the official blog post will not be posted. Note from IT Home: The server brand has not been updated and is still Windows Server 2022 in the preview version. In addition, Microsoft calls these versions Windows Server vNext instead of the Windows version that is already on the market.

IT House reported on March 14 that in addition to the Windows 11 Build 26080 preview update for the desktop, Microsoft also updated and launched the Windows Server Build 26080 preview update. As the latest preview version of the upcoming Windows Server Long Term Servicing Channel (LTSC), Windows Server Build 26080 provides Data Center Edition and Standard Edition, and users can choose desktop experience and Server Core installation options. This release also includes an annual channel for container hosts, and an Azure release specifically for virtual machine evaluation. IT House queries X social media. User feedback clicks the Copilot button in the lower right corner.

Server matching logic When nginx determines which server block to execute a request, it mainly focuses on the listen and server_name fields in the server block. The listen command listen field defines the IP and port of the server response. If the listen field is not explicitly configured, the default listening 0.0.0.0:80 (root) or 0.0.0.0:8080 (non-root) listen can be configured as: a combination of ip and port, a single ip, listening on port 80 by default, a single port, and listening on all ip interfaces by default A unixsocket path where the last entry is usually only used in different

Channel in Go language is a mechanism for communication and data synchronization between coroutines. Can be thought of as a special data type, similar to a queue or pipe, used to transfer data between different coroutines. Channel provides two main operations: send and receive. Both send and receive operations in a channel are blocking, which means that if no sender or receiver is ready, the operation will be blocked until a coroutine is ready to perform the corresponding operation, etc.

If you think there is no need to install a graphical interface when installing Ubuntu Server 11.04, let alone GNOME 3, which is not yet complete. . Or it should be built with ARCH+GNOME3. So please don't waste your time reading any more. It took 2 nights and a day and reinstalled N times. Finally something has come of it. It's not easy. Without further ado, let’s get to the point: Hardware: One ThinkPad (For X61) 2. Enter the boot options interface, select USB boot, and then choose to install Ubu
