Laravel 调用PING++
来源:互联网 发布:交换机端口号怎么看 编辑:程序博客网 时间:2024/06/06 01:15
class PayController extends Controller{ //支付 public function index(Request $request){ \Pingpp\Pingpp::setPrivateKeyPath(__DIR__ . '/your_rsa_private_key.pem');//私钥 $channel = (INT)(strtolower($request['payType']));//支付类型 //$extra 在使用某些渠道的时候,需要填入相应的参数,其它渠道则是 array() .具体见以下代码或者官网中的文档。其他渠道时可以传空值也可以不传。 $extra = array(); switch ($channel) { case 1: $channel = 'wx'; $ordertype = 0; $extra = array( );// \Pingpp\Pingpp::setPrivateKeyPath(__DIR__ . '/alipay.pem'); break; case 2: $channel = 'alipay'; $ordertype = 1; $extra = array( ); break; case 3: $channel = 'upacp'; $ordertype = 2; $extra = array( 'result_url' => 'http://www.yourdomain.com/result?code=' ); break; } \Pingpp\Pingpp::setApiKey('平台的key'); DB::table('orders')->where('order_sn',$request['orderNo'])->update(['pay_type'=>$ordertype]); try { $ch = \Pingpp\Charge::create( array( 'subject' => '-'.$request['orderNo'],//交易的title 'body' => '-'.$request['orderNo'],//交易的订单号 'amount' =>$amount , 'order_no' => $request['orderNo'].rand(1000,9999),//防止订单号重复 'currency' => 'cny', 'extra' => $extra, 'channel' => $channel, 'client_ip' => $_SERVER['REMOTE_ADDR'], 'app' => array('id' => '平台appid') ) ); return json_encode(array('code'=>0,'msg'=>'成功','data'=>json_decode($ch))); } catch (\Pingpp\Error\Base $e) { header('Status: ' . $e->getHttpStatus()); echo($e->getHttpBody()); } } //支付完事之后的事情 public function webhooks(Request $request){ $raw_data = file_get_contents('php://input');//这是在ping++设置的回调传回来的值 $headers = \Pingpp\Util\Util::getRequestHeaders(); $signature = isset($headers['X-Pingplusplus-Signature']) ? $headers['X-Pingplusplus-Signature'] : NULL; $pub_key_path =__DIR__ . '/public_key.pem';//公钥 $result = $this -> verify_signature($raw_data, $signature, $pub_key_path);//验证身份 if ($result === 1) { // 验证通过 $event = json_decode($raw_data, true); if ($event['type'] == 'charge.succeeded') { $charge = $event['data']['object']; $order_sn = $charge['order_no'];//订单号 $return_num = $charge['id'];//付款成功后的回执 //更改订单状态 do something by myself } } elseif ($result === 0) { http_response_code(400); echo 'verification failed'; exit; } else { http_response_code(400); echo 'verification error'; exit; } } //验证安全 public function verify_signature($raw_data, $signature, $pub_key_path) { $pub_key_contents = file_get_contents($pub_key_path); // php 5.4.8 以上,第四个参数可用常量 OPENSSL_ALGO_SHA256 return openssl_verify($raw_data, base64_decode($signature), $pub_key_contents, 'sha256'); }}
阅读全文
0 0
- Laravel 调用PING++
- laravel ping+微信扫码
- laravel框架调用Guzzle
- laravel 调用html文件
- ping命令java调用
- c#调用ping命令
- laravel中pipeline中间件调用
- java调用cmd命令ping
- 调用laravel函数的3种方法
- laravel 5.2 form模块调用时出错
- yii框架跨域传值到laravel,接口调用
- Laravel-mix及模板调用问题
- Laravel中中间件调用过程:Part 1
- 在Linux下面的调用ping
- c#调用ping网络连接检查
- C#调用CMD中的PING命令
- 一个并发调用ping 的python 脚本
- android手机调用linux ping命令
- SVN 撤回(回滚)提交的代码
- FFmpeg在android上多媒体编程
- 堆栈 and 递归 获取无限极树形菜单
- 奋斗群群赛16总结与心得
- 青少年武术入门 少林拳.pdf
- Laravel 调用PING++
- MySql主从同步
- SSL P2744 树塔狂想曲
- Install Linux upon Windows10 and some set-up
- es6常用方法总结
- PXC(Percona-Xtradb-Cluster) 集群问题补充
- 在重定向,转发中关于路径问题的总结
- SpringBoot学习-(十二)SpringBoot中建立WebSocket连接
- Spring Boot学习笔记03--深入了解SpringBoot的启动过程