Pingpp\Pingpp::setApiKey PHP Method

setApiKey() public static method

Sets the API key to be used for requests.
public static setApiKey ( string $apiKey )
$apiKey string
    public static function setApiKey($apiKey)
    {
        self::$apiKey = $apiKey;
    }

Usage Example

Ejemplo n.º 1
0
 public function pay($runValidation = true)
 {
     if ($runValidation && !$this->validate()) {
         return false;
     }
     if ($this->_order->status !== Order::STATUS_UNPAID) {
         return false;
     }
     require_once Yii::getAlias('@vendor') . "/pingplusplus/pingpp-php/init.php";
     \Pingpp\Pingpp::setApiKey(Yii::$app->params['pingpp.apiKey']);
     try {
         $extra = [];
         switch ($this->channel) {
             case self::CHANNEL_ALIPAY_WAP:
                 $extra = ['success_url' => Yii::$app->request->hostInfo . '/#/order/detail/' . $this->_order->id, 'cancel_url' => Yii::$app->request->hostInfo . '/#/order/pay/' . $this->_order->id];
                 break;
             case self::CHANNEL_WX_PUB:
                 Yii::$app->session->open();
                 $extra = ['open_id' => Yii::$app->session['wechatOpenid']];
                 break;
             case self::CHANNEL_ALIPAY_PC_DIRECT:
                 $extra = ['success_url' => Yii::$app->request->hostInfo . '/#/order/detail/' . $this->_order->id];
                 break;
             default:
                 throw new InvalidValueException('支付渠道错误!');
         }
         $ch = \Pingpp\Charge::create(['subject' => '笑e购订单', 'body' => '笑e购(xiaoego.com)订单,订单号:' . $this->_order->order_sn, 'amount' => bcmul($this->_order->real_fee, 100), 'order_no' => $this->_order->order_sn, 'currency' => 'cny', 'extra' => $extra, 'channel' => $this->channel, 'client_ip' => Yii::$app->request->userIP, 'time_expire' => $this->_order->timeout + 1800, 'app' => ['id' => Yii::$app->params['pingpp.appId']], 'description' => mb_strlen($this->_order->description, 'UTF-8') <= 255 ? $this->_order->description : substr($this->_order->description, 0, 253) . '……']);
         return $ch;
     } catch (\Exception $e) {
         throw $e;
     }
 }
All Usage Examples Of Pingpp\Pingpp::setApiKey