Home  >  Article  >  php教程  >  thinkphp整合pingpp第三方支付平台

thinkphp整合pingpp第三方支付平台

WBOY
WBOYOriginal
2016-06-07 11:36:301315browse

thinkphp整合pingpp第三方支付平台
1:下载pingpp sdk php版
结构如下图
thinkphp整合pingpp第三方支付平台
thinkphp整合pingpp第三方支付平台
thinkphp整合pingpp第三方支付平台
2:在thinkphp 的Library/Vendor/下面建立一个Pay文件夹如图
3:把第一张图中的标红的文件及文件夹复制到这个Pay文件夹中
4:测试
在控制器里引入init.pp文件,把下面的代码,放入一个控制器里面测试就ok了。
public function _initialize()
{
vendor( "Pingpp.init");
}
public function index()
{

$input_data = json_decode(file_get_contents('php://input' ), true);
if (empty($input_data[ 'channel']. 'alipay') || empty($input_data[ 'amount']. '10')) {
echo 'channel or amount is empty';
exit();
}
$channel = strtolower($input_data['channel'].'alipay' );//支付方式
$amount = $input_data[ 'amount']. '10'; //支付金额
$orderno = substr(md5(time()), 0, 12); //订单号
$client_ip=$input_data[ 'client_ip']. '127.0.0.1'; //客户端ip
$subject=$input_data[ 'subject']. '服务'; //商品名称
$body=$input_data[ 'body']. '服务'; //商品描述信息

//$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(
'order_no' => $orderno,
'amount' => $amount,
'app' => array ('id' => 'app_1Gqj58ynP0mHeX1q'),
'channel' => $channel,
'currency' => 'cny',
'client_ip' => $client_ip,
'subject' => $subject,
'body' => $body,
'extra' => $extra
)
);
echo $ch;
} catch (\Pingpp\Error\Base $e) {
header( 'Status: ' . $e->getHttpStatus());
echo($e->getHttpBody());
}





}

5:结果
thinkphp整合pingpp第三方支付平台

AD:真正免费,域名+虚机+企业邮箱=0元

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn