1.去ping++ 官网下载 php 版本的sdk
https://github.com/PingPlusPlus/pingpp-php
2.下载完后 解压 并重命名此文件夹为 PingppSDK
3.开始写测试代码
找到此目录下的IndexController
4.找到_initialize() 方法 并在里面插入一行代码 Vendor(‘PingppSDK.init’);
5.添加一个测试方法
public function test() {
if (empty($_GET['channel']) || empty($_GET['amount'])) {
echo 'channel or amount is empty';
exit();
}
$channel = strtolower($_GET['channel']);
$amount = $_GET['amount'];
$orderNo = substr(md5(time()), 0, 12);
//$extra 在使用某些渠道的时候,需要填入相应的参数,其它渠道则是 array() .具体见以下代码或者官网中的文档。其他渠道时可以传空值也可以不传。
$extra = array();
switch ($channel) {
case 'alipay_wap' :
$extra = array('success_url' => 'http://www.yourdomain.com/success', 'cancel_url' => 'http://www.yourdomain.com/cancel');
break;
case 'upmp_wap' :
$extra = array('result_url' => 'http://www.yourdomain.com/result?code=');
break;
case 'bfb_wap' :
$extra = array('result_url' => 'http://www.yourdomain.com/result?code=', 'bfb_login' => true);
break;
case 'upacp_wap' :
$extra = array('result_url' => 'http://www.yourdomain.com/result');
break;
case 'wx_pub' :
$extra = array('open_id' => 'Openid');
break;
case 'wx_pub_qr' :
$extra = array('product_id' => 'Productid');
break;
case 'yeepay_wap' :
$extra = array('product_category' => '1', 'identity_id' => 'your identity_id', 'identity_type' => 1, 'terminal_type' => 1, 'terminal_id' => 'your terminal_id', 'user_ua' => 'your user_ua', 'result_url' => 'http://www.yourdomain.com/result');
break;
case 'jdpay_wap' :
$extra = array('success_url' => 'http://www.yourdomain.com', 'fail_url' => 'http://www.yourdomain.com', 'token' => 'dsafadsfasdfadsjuyhfnhujkijunhaf');
break;
}
\Pingpp\Pingpp::setApiKey('sk_test_ibbTe5jLGCi5rzfH4OqPW9KC');
try {
$ch = \Pingpp\Charge::create(array('subject' => 'Your Subject', 'body' => 'Your Body', 'amount' => $amount, 'order_no' => $orderNo, 'currency' => 'cny', 'extra' => $extra, 'channel' => $channel,
'client_ip' => get_client_ip(), 'app' => array('id' => 'app_1Gqj58ynP0mHeX1q')));
echo $ch;
} catch (\Pingpp\Error\Base $e) {
//header('Status: ' . $e->getHttpStatus());
header("Content-type:text/html;charset=utf-8");
echo($e->getHttpBody());
}
}
6.浏览器访问该方法
http://localhost/你项目的名称/index.php?g=&m=Index&a=test&channel=alipay_wap&amount=123
结果
成功集成ping++ 了 剩下的交易操作 可以看ping++ 官网文档了