ping++支付

要根据自己实际业务需求进行更改,不可照搬
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' => "",//商品的标题,该参数最长为 32Unicode 字符,银联全渠道( upacp / upacp_wap )限制在 32 个字节。
                        'body' => "",//商品的描述信息,该参数最长为 128Unicode 字符,yeepay_wap 对于该参数长度限制为 100Unicode 字符。
                        '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();
                }
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值