Example #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;
     }
 }
Example #2
0
 public function __construct()
 {
     parent::__construct();
     //api加密
     $time_stamp = $this->input->get('time');
     $token = $this->input->get('token');
     $secret = '99dayin_api_secrete';
     if (empty($time_stamp) || empty($token)) {
         exit('url参数错误!无授权参数');
     }
     $md5 = md5($time_stamp . $secret);
     if ($md5 != $token) {
         exit('加密错误!');
     }
     //引入bomb
     $this->bmobUser = new BmobUser();
     //引入ping++
     $test_key = 'sk_test_0CKaPS8CmDeLfr9CCOmXHGGS';
     $live_key = 'sk_live_bOz9YlaOHrS7dFw9yYlUif7R';
     $this->pingpp_app_id = 'app_SO0anHPWznHCbL0y';
     \pingpp\Pingpp::setApiKey($live_key);
     //解析post数据,以json格式接收的数据
     if ($this->input->server('CONTENT_TYPE') === 'application/json') {
         $this->post_data = json_decode($this->input->raw_input_stream);
     } else {
     }
 }
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $config = config('pingpp');
     $this->app->bind('pingpp', function () use($config) {
         Pingpp::setApiKey($config['live'] === true ? $config['live_secret_key'] : $config['test_secret_key']);
         return new PingppCollertion();
     });
 }
Example #4
0
 /**
  * 重新支付
  * @return string
  * @author zhengqian@dajiayao.cc
  */
 public function rePay()
 {
     $buyerId = $this->buyerId;
     $wxUser = Buyer::find($buyerId)->wxUser;
     if (!$wxUser) {
         return RestHelp::encodeResult(24000, "user illegality");
     }
     $inputData = $this->inputData->all();
     $validator = Validator::make($inputData, ['orderNumber' => 'required']);
     if ($validator->fails()) {
         return RestHelp::parametersIllegal($validator->messages()->first());
     }
     $objOrder = Order::where('order_number', $inputData['orderNumber'])->first();
     $objShop = Shop::find($objOrder->shop_id);
     if (!$objShop) {
         return RestHelp::encodeResult(21000, sprintf("shop short id %s not found in db", $objOrder->shop_id));
     }
     //查找价格
     $itemTotal = $objOrder->item_total;
     $grandTotal = $objOrder->grand_total;
     $payment = new Payment();
     $payment->serial_number = OrderHelper::getPaymentSerialNumber(1);
     $payment->payment_number = '';
     $payment->order_id = $objOrder->id;
     $payment->order_number = $inputData['orderNumber'];
     $payment->buyer_id = $buyerId;
     $payment->amount = $itemTotal;
     $payment->channel = Payment::PAYMENT_CHANNEL_PXX;
     $payment->type = Payment::PAYMENT_TYPE_WX;
     $payment->status = Order::PAY_STATUS_NO;
     $payment->save();
     $subject = '';
     //32
     $body = '';
     //128
     foreach ($objOrder->orderItems as $orderItem) {
         $subject .= $orderItem->items->title . "*" . $orderItem->items->spec . "*" . $orderItem->quantity . ",";
         $body .= $orderItem->items->title . $orderItem->items->spec . $orderItem->quantity;
     }
     try {
         \Pingpp\Pingpp::setApiKey('sk_live_3dKEivmziedjzitFhaHL7gYF');
         $ch = \Pingpp\Charge::create(array('order_no' => $payment->serial_number, 'app' => array('id' => 'app_XTOW5SXTWLGCGKef'), 'channel' => 'wx_pub', 'amount' => $grandTotal * 100, 'client_ip' => $this->inputData->ip(), 'currency' => 'cny', 'subject' => mb_substr($subject, 0, 32), 'body' => mb_substr($body, 0, 128), 'extra' => array('open_id' => $wxUser->openid)));
     } catch (\Exception $e) {
         return RestHelp::encodeResult(22003, $e->getMessage(), ['orderNum' => $inputData['orderNumber']]);
     }
     //写入paytmentLOg
     $paymentLog = new PaymentLog();
     $paymentLog->payment_id = $payment->id;
     $paymentLog->channel = Payment::PAYMENT_CHANNEL_PXX;
     $paymentLog->request_data = $ch;
     $paymentLog->respond_data = '';
     $paymentLog->save();
     //保存支付流水号
     $payment->payment_number = json_decode($ch)->id;
     $payment->save();
     return RestHelp::success(['orderNumber' => $inputData['orderNumber'], 'paymentNumber' => $payment->serial_number, 'charge' => json_decode($ch, true)]);
 }
Example #5
0
 function __construct()
 {
     require_once '/application/third_party/pingpp/init.php';
     $this->appId = "app_fX9ijPX1qTK4DeLK";
     \Pingpp\Pingpp::setApiKey(\Pingpp\Pingpp::getApiKey());
     $this->load->model('order_model');
     $this->load->model('user_payment_model');
     $this->load->model('withdraw_model');
 }
 /**
  *
  */
 public function register()
 {
     $this->app->singleton(['pingpp.charge.create' => Create::class], function () {
         list($sk, $pk, $config) = $this->readConfig();
         Pingpp::setApiKey($sk);
         $creator = new Create();
         $creator->setConfig($config);
         return $creator;
     });
 }
 /**
  * @throws InvalidConfigException
  */
 public function init()
 {
     if ($this->apiKey === null) {
         throw new InvalidConfigException('The apiKey property must be set.');
     }
     if ($this->appId === null) {
         throw new InvalidConfigException('The appId property must be set.');
     }
     Pingpp::setApiKey($this->apiKey);
 }
Example #8
0
 public function init()
 {
     \Pingpp\Pingpp::setApiKey($this->live ? $this->live_secret_key : $this->test_secret_key);
     if (!empty($this->private_key_path)) {
         if (file_exists($this->private_key_path)) {
             throw new InvalidConfigException('The private key file not exists.');
         }
         \Pingpp\Pingpp::setPrivateKeyPath($this->private_key_path);
     }
 }
Example #9
0
 /**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function pay()
 {
     \Pingpp\Pingpp::setApiKey('sk_test_urT4i5iPOCiHPmj5K0uLO0GK');
     $res = \Pingpp\Charge::create(array('order_no' => '0123456789', 'amount' => '100', 'app' => array('id' => 'app_9iLSeP8Oi5SGznbj'), 'channel' => 'upacp_pc', 'currency' => 'cny', 'client_ip' => '127.0.0.1', 'subject' => 'Your Subject', 'body' => 'Your Body', 'extra' => array('success_url' => 'http://www.jindanlan.com/')));
     \Debugbar::info($res);
     $content = $res;
     $status = 200;
     $value = "text/json";
     return response($content, $status)->header('Content-Type', $value);
 }
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $config = config('pingpp');
     $this->app->bind('pingpp', function () use($config) {
         Pingpp::setApiKey($config['live'] === true ? $config['live_secret_key'] : $config['test_secret_key']);
         if (!empty($config['private_key_path']) && file_exists($config['private_key_path'])) {
             Pingpp::setPrivateKeyPath($config['private_key_path']);
         }
         return new PingppCollertion();
     });
 }
 private static function connectionCheck()
 {
     try {
         \Pingpp\Pingpp::setApiKey(static::$apiKey);
         \Pingpp\Charge::retrieve(static::$exampleChargeId);
     } catch (Exception $e) {
         if ($e instanceof \Pingpp\Error\ApiConnection) {
             throw $e;
         }
     }
 }
Example #12
0
 public function payTestOp()
 {
     \Pingpp\Pingpp::setApiKey('sk_test_vP8WX9KKG4CSmfDGCSPm1WTO');
     $extra = array();
     try {
         $ch = \Pingpp\Charge::create(array('order_no' => '123456789233', 'app' => array('id' => 'app_u1yjzHbvvLeLybbT'), 'channel' => 'alipay', 'amount' => 100, 'client_ip' => '127.0.0.1', 'currency' => 'cny', 'subject' => 'Your Subject', 'body' => 'Your Body', 'extra' => $extra));
         echo $ch;
     } catch (\Pingpp\Error\Base $e) {
         header('Status: ' . $e->getHttpStatus());
         echo $e->getHttpBody();
     }
 }
Example #13
0
 /**
  * @throws InvalidConfigException
  */
 public function init()
 {
     if ($this->apiKey === null) {
         throw new InvalidConfigException('The apiKey property must be set.');
     }
     if ($this->appId === null) {
         throw new InvalidConfigException('The appId property must be set.');
     }
     Pingpp::setApiKey($this->apiKey);
     if (!empty($this->privateKeyPath)) {
         $privateKeyFullPath = Yii::getAlias($this->privateKeyPath);
         if (!file_exists($privateKeyFullPath)) {
             throw new InvalidConfigException('The private key file not exists.');
         }
         Pingpp::setPrivateKeyPath($privateKeyFullPath);
     } elseif (!empty($this->privateKey)) {
         Pingpp::setPrivateKey($this->privateKey);
     }
 }
Example #14
0
 public function __construct($orderId = '')
 {
     parent::__construct();
     $this->userId = $this->CI->session->userdata('userId');
     $this->cart = new MY_Cart();
     $this->bmobOrder = new BmobObject('Order');
     //引入ping++
     require_once APPPATH . 'third_party/pingpp/init.php';
     $test_key = 'sk_test_0CKaPS8CmDeLfr9CCOmXHGGS';
     $live_key = 'sk_live_bOz9YlaOHrS7dFw9yYlUif7R';
     $this->pingpp_app_id = 'app_SO0anHPWznHCbL0y';
     \pingpp\Pingpp::setApiKey($live_key);
     //订单号不为空,则从bomb拉去信息
     if (!empty($orderId)) {
         $this->orderId = $orderId;
         $res = $this->bmobOrder->get($orderId);
         $orderInfo = $res->results[0];
         $this->totalPrice = $orderInfo->totalPrice;
     }
 }
Example #15
0
<?php

/* *
 * Ping++ Server SDK
 * 说明:
 * 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写, 并非一定要使用该代码。
 * 该代码仅供学习和研究 Ping++ SDK 使用,只是提供一个参考。
*/
require dirname(__FILE__) . '/../init.php';
// api_key、app_id 请从 [Dashboard](https://dashboard.pingxx.com) 获取
$api_key = 'sk_test_ibbTe5jLGCi5rzfH4OqPW9KC';
$app_id = 'app_1Gqj58ynP0mHeX1q';
\Pingpp\Pingpp::setApiKey($api_key);
try {
    $tr = \Pingpp\Transfer::create(array('amount' => 100, 'order_no' => date('YmdHis') . microtime(true) % 1 * 1000 . mt_rand(0, 9999), 'currency' => 'cny', 'channel' => 'wx_pub', 'app' => array('id' => $app_id), 'type' => 'b2c', 'recipient' => 'o9zpMs9jIaLynQY9N6yxcZ', 'description' => 'testing', 'extra' => array('user_name' => 'User Name', 'force_check' => false)));
    echo $tr;
} catch (\Pingpp\Error\Base $e) {
    header('Status: ' . $e->getHttpStatus());
    echo $e->getHttpBody();
}
Example #16
0
 /**
  * 生成订单
  * @return string
  * @author zhengqian@dajiayao.cc
  */
 public function create()
 {
     //        $inputData = $this->inputData->all();
     $buyerId = $this->buyerId;
     $wxUser = Buyer::find($buyerId)->wxUser;
     if (!$wxUser) {
         return RestHelp::encodeResult(24000, "user illegality");
     }
     $inputData = json_decode(file_get_contents("php://input"), true);
     $validator = Validator::make($inputData, ['shopShortId' => 'required', 'items' => 'required', 'deliverAddressId' => 'required', 'paymentType' => 'required', "shopType" => '', 'orderNumber' => '', "isAnonymous" => 'required|Boolean']);
     if ($validator->fails()) {
         return RestHelp::parametersIllegal($validator->messages()->first());
     }
     if (!isset($inputData['items']) or !is_array($inputData['items'])) {
         return RestHelp::encodeResult(23003, 'item must be array');
     }
     $objShop = Shop::getShopByShort($inputData['shopShortId']);
     if (!$objShop) {
         return RestHelp::encodeResult(21000, sprintf("shop short id %s not found in db", $inputData['shopShortId']));
     }
     $deliver = BuyerAddress::find($inputData['deliverAddressId']);
     if (!$deliver) {
         return RestHelp::encodeResult(23001, sprintf("deliver address id: %s not found in db", $inputData['deliverAddressId']));
     }
     if (!isset($inputData['orderNumber'])) {
         $orderNumber = OrderHelper::getOrderSerialNumber();
     } else {
         $orderNumber = $inputData['orderNumber'];
     }
     $deliverAddressId = $inputData['deliverAddressId'];
     $shopId = $objShop->id;
     $itemTotal = 0;
     $postageFlag = 0;
     $shelfItems = $objShop->getItemsOnShelf();
     //检查商品合法性、库存等等
     foreach ($inputData['items'] as $item) {
         if (!array_key_exists('id', $item) or !array_key_exists('count', $item)) {
             return RestHelp::encodeResult(23005, "items not correct");
         }
         $objItem = Item::find($item['id']);
         $itemTotal += $objItem->price * $item['count'];
         if ($objItem->postage_type == Item::POSTAGE_TYPE_BUYER) {
             $postageFlag++;
         }
         if ($objItem->sale_status == Item::SALE_STATUS_NO) {
             return RestHelp::encodeResult(23006, sprintf("%s已停售", $objItem->title));
         }
         if ($objItem->shelf_status == Item::SHELF_STATUS_NO or !array_key_exists($objItem->id, $shelfItems)) {
             return RestHelp::encodeResult(23006, sprintf("%s已下架", $objItem->title));
         }
         //库存
         if ($objItem->stock < $item['count']) {
             return RestHelp::encodeResult(23006, sprintf("%s库存不足", $objItem->title));
         }
     }
     $postage = $postageFlag ? $this->settingService->getSettingByKey(Setting::KEY_ORDER_POSTAGE)->value : 0;
     $grandTotal = $itemTotal + $postage;
     $sessionTotal = WxUserKv::getValue(Buyer::find($this->buyerId)->wxUser->id, WxUserKv::BUYER_CHECK_PRICE);
     if ((string) $sessionTotal != (string) $grandTotal) {
         return RestHelp::encodeResult(22002, "illegal operation");
     }
     $discount = 0;
     $orderType = Order::PAYMENT_TYPE_WX;
     //如果传入了订单号
     if (isset($inputData['orderNumber'])) {
         //update
         $objOrder = Order::where('order_number', $inputData['orderNumber'])->first();
         if (!$objOrder) {
             return RestHelp::encodeResult(22001, "the order not found");
         }
         //new
         try {
             $orderId = $this->orderService->update($objOrder, $itemTotal, $grandTotal, $discount, $grandTotal - $discount, $inputData['isAnonymous'] ? 1 : 0, $postage, $orderType, $deliverAddressId);
         } catch (\Exception $e) {
             return RestHelp::encodeResult(23004, $e->getMessage());
         }
     } else {
         //new
         try {
             $orderId = $this->orderService->create($orderNumber, $shopId, $this->buyerId, $itemTotal, $grandTotal, $discount, $grandTotal - $discount, $postage, $orderType, $deliverAddressId, $inputData['isAnonymous'] ? 1 : 0, null, null);
         } catch (\Exception $e) {
             return RestHelp::encodeResult(23004, $e->getMessage());
         }
         //减少库存
         $commissonTotal = 0;
         foreach ($inputData['items'] as $item) {
             $objItem = Item::find($item['id']);
             $objItem->stock -= $item['count'];
             $objItem->save();
             //计算挨个佣金
             $commissonTotal += $objItem->commission * $item['count'];
         }
         //生成佣金表数据
         $commisson = OrderCommission::firstOrNew(['order_id' => $orderId]);
         $commisson->amount = $objShop->is_direct_sale == 'Y' ? 0 : $commissonTotal;
         $commisson->status = OrderCommission::STATUS_UNCONFIRMED;
         $commisson->save();
         //生成seller commisson
         $sellerCommission = SellerCommission::firstOrNew(['order_id' => $orderId, 'seller_id' => $objShop->seller_id]);
         $sellerCommission->amount = $objShop->is_direct_sale == 'Y' ? 0 : $commissonTotal;
         $sellerCommission->status = SellerCommission::STATUS_UNCONFIRMED;
         $sellerCommission->save();
     }
     $subject = '';
     //32
     $body = '';
     //128
     $itemIdList = \DB::table('order_items')->where('order_id', $orderId)->lists('item_id');
     foreach ($inputData['items'] as $item) {
         if (isset($inputData['orderNumber'])) {
             $orderItem = OrderItem::where('order_id', $orderId)->where('item_id', $item['id'])->first();
             $quantity = $orderItem ? $orderItem->quantity : 0;
             $count = $item['count'];
             $balance = $count - $quantity;
             $objItem = Item::find($item['id']);
             $objItem->stock -= $balance;
             $objItem->save();
             OrderItem::where('order_id', $orderId)->where('item_id', $item['id'])->forceDelete();
             //如果支付失败,返回修改删除了某个商品,则恢复库存 Step 1  @author zhengqian
             foreach ($itemIdList as $k => $itid) {
                 if ($item['id'] == $itid) {
                     unset($itemIdList[$k]);
                 }
             }
         }
         $orderItem = new OrderItem();
         $orderItem->order_id = $orderId;
         $orderItem->item_id = $item['id'];
         $objItem = Item::find($item['id']);
         $orderItem->name = $objItem->name;
         $subject .= $objItem->title . "*" . $objItem->spec . "*" . $objItem->{$item}['count'] . ",";
         $body .= $objItem->title . $objItem->spec . $objItem->{$item}['count'];
         $orderItem->title = $objItem->title;
         $orderItem->code = $objItem->code;
         $orderItem->barcode = $objItem->barcode;
         $orderItem->type = ItemType::find($objItem->type_id)->name;
         $orderItem->quantity = $item['count'];
         $orderItem->price = $objItem->price;
         $orderItem->item_total = $objItem->price * $item['count'];
         $commissionsRate = $this->settingService->getSettingByKey(Setting::KEY_COMMISSIONS_RATE);
         if (!$commissionsRate) {
             $commissionsRate = Setting::DEFAULT_KEY_COMMISSIONS_RATE;
         } else {
             $commissionsRate = $commissionsRate->value;
         }
         $orderItem->commission = $orderItem->item_total * $commissionsRate;
         $orderItem->save();
     }
     //如果支付失败,返回修改删除了某个商品,则恢复库存 Step 2 @author zhengqian
     if (isset($inputData['orderNumber'])) {
         foreach ($itemIdList as $itid) {
             $orderItem = OrderItem::where('order_id', $orderId)->where('item_id', $itid)->first();
             $quantity = $orderItem->quantity;
             $objItem = Item::find($itid);
             $objItem->stock += $quantity;
             $objItem->save();
             OrderItem::where('order_id', $orderId)->where('item_id', $itid)->forceDelete();
         }
     }
     $payment = new Payment();
     $payment->serial_number = OrderHelper::getPaymentSerialNumber(1);
     $payment->payment_number = '';
     $payment->order_id = $orderId;
     $payment->order_number = Order::find($orderId)->order_number;
     $payment->buyer_id = $this->buyerId;
     $payment->amount = $itemTotal;
     $payment->channel = Payment::PAYMENT_CHANNEL_PXX;
     $payment->type = Payment::PAYMENT_TYPE_WX;
     $payment->status = Order::PAY_STATUS_NO;
     $payment->save();
     try {
         \Pingpp\Pingpp::setApiKey('sk_live_3dKEivmziedjzitFhaHL7gYF');
         $ch = \Pingpp\Charge::create(array('order_no' => $payment->serial_number, 'app' => array('id' => 'app_XTOW5SXTWLGCGKef'), 'channel' => 'wx_pub', 'amount' => $sessionTotal * 100, 'client_ip' => $this->inputData->ip(), 'currency' => 'cny', 'subject' => mb_substr($subject, 0, 32), 'body' => mb_substr($body, 0, 128), 'extra' => array('open_id' => $wxUser->openid)));
     } catch (\Exception $e) {
         return RestHelp::encodeResult(22003, $e->getMessage(), ['orderNum' => $orderNumber]);
     }
     //写入paytmentLOg
     $paymentLog = new PaymentLog();
     $paymentLog->payment_id = $payment->id;
     $paymentLog->channel = Payment::PAYMENT_CHANNEL_PXX;
     $paymentLog->request_data = $ch;
     $paymentLog->respond_data = '';
     $paymentLog->save();
     //保存支付流水号
     $payment->payment_number = json_decode($ch)->id;
     $payment->save();
     return RestHelp::success(['orderNumber' => $orderNumber, 'paymentNumber' => $payment->serial_number, 'charge' => json_decode($ch, true)]);
 }
Example #17
0
 public function __construct($module)
 {
     $this->module = $module;
     $conf = $this->getConf();
     \Pingpp\Pingpp::setApiKey($conf['key']);
 }
Example #18
0
<?php

/* *
 * Ping++ Server SDK
 * 说明:
 * 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写, 并非一定要使用该代码。
 * 该代码仅供学习和研究 Ping++ SDK 使用,只是提供一个参考。
 */
require_once dirname(__FILE__) . '/../init.php';
\Pingpp\Pingpp::setApiKey('YOUR-KEY');
$ch = \Pingpp\Charge::retrieve('CHARGE_ID');
$ch->refunds->create(array('amount' => 10, 'description' => 'Your Descripton'));
Example #19
0
 public function __construct()
 {
     Ping::setApiKey(C('MYLINE_KEY'));
 }
Example #20
0
 /**
  * 支付订单1
  */
 public function payOrderStep1Op()
 {
     \Pingpp\Pingpp::setApiKey('sk_test_vP8WX9KKG4CSmfDGCSPm1WTO');
     $mod_order = Model('service_yuyue_api');
     $mod_service = Model('service');
     //获取appId
     $appId = $_POST['appId'];
     $yuyueId = $_GET['yuyue_id'];
     //根据服务预约id找出记录
     $where['yuyue_id'] = $yuyueId;
     $order = $mod_order->getOne($where);
     $serviceId = $order['yuyue_service_id'];
     $service = $mod_service->getOne(array('service_id' => $serviceId));
     //取出支付订单id
     $orderId = $order['yuyue_pay_number'];
     //取出订单金额
     $amount = $service['service_now_price'] * 100;
     //取出交易名称
     $orderName = "[科研助手]" . $service['service_name'];
     //交易描述
     $orderDesc = $service['service_name'];
     //获取请求ip
     $clientIp = "";
     //获取支付方式
     $channel = $_POST['channel'];
     //        'app_u1yjzHbvvLeLybbT'
     $extra = array();
     try {
         $ch = \Pingpp\Charge::create(array('order_no' => $orderId, 'app' => array('id' => $appId), 'channel' => 'alipay', 'amount' => $amount, 'client_ip' => $clientIp, 'currency' => 'cny', 'subject' => $orderName, 'body' => $orderDesc, 'extra' => $extra));
         echo $ch;
     } catch (\Pingpp\Error\Base $e) {
         header('Status: ' . $e->getHttpStatus());
         echo $e->getHttpBody();
     }
 }
 /**
  * @author : Comer
  * @date   : 2015/4/20 16:20
  *
  * @desc     通过charge的ID查询支付状态
  * @param
  * @return   null
  */
 public function getPaystateById($chargeId)
 {
     //引入ping++类库文件
     require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/pingpp-php-master/init.php';
     \Pingpp\Pingpp::setApiKey(C('MYLINE_KEY'));
     $Charge = \Pingpp\Charge::retrieve($chargeId);
     $input_data = json_decode($Charge, true);
     if ($input_data['object'] == 'charge' && $input_data['paid'] == true) {
         return true;
     } else {
         if ($input_data['object'] == 'charge' && $input_data['paid'] == false) {
             return false;
         }
     }
 }
 public function promotion_pay()
 {
     $api_key = C('API_KEY');
     $api_id = C('API_ID');
     $input_data = json_decode(file_get_contents('php://input'), true);
     if (empty($input_data['channel']) || empty($input_data['amount'])) {
         echo 'channel or amount is empty';
         exit;
     }
     $channel = strtolower($input_data['channel']);
     $submission_id = $input_data['submission_id'];
     $amount = 0;
     $choice1 = $input_data['choice1'];
     if ($choice1 == '1a') {
         $amount = 3000;
     } elseif ($choice1 == '1b') {
         $amount = 8000;
     } elseif ($choice1 == '1c') {
         $amount = 12000;
     } elseif ($choice1 == '1d') {
         $amount = 18000;
     }
     $choice2 = $input_data['choice2'];
     $prices = [3000, 15000, 10000, 1000, 5000, 12000, 500, 200];
     $promotion = $choice1;
     for ($i = 0; $i < count($choice2); $i++) {
         $amount += $choice2[$i] * $prices[$i];
         $promotion .= ',' . $choice2[$i];
     }
     $amount *= 100;
     if ($_SESSION['urole'] == 2) {
         $amount = 1;
     }
     $orderNo = $input_data['order_no'];
     M('promotion')->where(array('contest_id' => C('CONTESTID'), 'user_id' => $_SESSION['uid'], 'submission_id' => $submission_id, 'promotion' => $promotion, 'price' => $amount / 100, 'ispaied' => 0))->delete();
     M('promotion')->data(array('contest_id' => C('CONTESTID'), 'user_id' => $_SESSION['uid'], 'submission_id' => $submission_id, 'promotion_code' => $orderNo, 'promotion' => $promotion, 'timestamp' => time(), 'price' => $amount / 100))->add();
     \Pingpp\Pingpp::setPrivateKeyPath('Public/rsa_private_key.pem');
     /**
      * $extra 在使用某些渠道的时候,需要填入相应的参数,其它渠道则是 array()。
      * 以下 channel 仅为部分示例,未列出的 channel 请查看文档 https://pingxx.com/document/api#api-c-new
      */
     $extra = array();
     $extra['context'] = 'promotion';
     $extra['submission_id'] = $submission_id;
     switch ($channel) {
         case 'alipay_wap':
             $extra = array('success_url' => C('SITE_PREFIX') . U('Pay/promotion_pay_success', array('submission_id' => $submission_id, 'promotion_code' => $orderNo)), 'cancel_url' => C('SITE_PREFIX') . U('Pay/promotion_pay_cancel', array('submission_id' => $submission_id, 'promotion_code' => $orderNo)));
             break;
         case 'bfb_wap':
             $extra = array('result_url' => 'http://example.com/result', 'bfb_login' => true);
             break;
         case 'upacp_wap':
             $extra = array('result_url' => 'http://example.com/result');
             break;
         case 'wx_pub':
             $extra = array('open_id' => 'openidxxxxxxxxxxxx');
             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://example.com/result');
             break;
         case 'jdpay_wap':
             $extra = array('success_url' => 'http://example.com/success', 'fail_url' => 'http://example.com/fail', 'token' => 'dsafadsfasdfadsjuyhfnhujkijunhaf');
             break;
     }
     $subject = '成功设计大赛作品推广 ' . $submission_id;
     \Pingpp\Pingpp::setApiKey($api_key);
     try {
         $ch = \Pingpp\Charge::create(array('subject' => $subject, 'body' => '快来支付吧', 'amount' => $amount, 'order_no' => $orderNo, 'currency' => 'cny', 'extra' => $extra, 'channel' => $channel, 'client_ip' => get_client_ip(), 'app' => array('id' => $api_id)));
         echo $ch;
     } catch (\Pingpp\Error\Base $e) {
         // 捕获报错信息
         if ($e->getHttpStatus() != NULL) {
             header('Status: ' . $e->getHttpStatus());
             echo $e->getHttpBody();
         } else {
             echo $e->getMessage();
         }
     }
 }
Example #23
0
        $id=$cancle_id;
    }
}



//生成订单

$t=time();
$orderNo = substr($id, 0, 8).substr($t_openid,21).$t;
$orderNo=str_replace('-','',$orderNo);

//ping++ part

//\Pingpp\Pingpp::setApiKey('sk_test_SSarLCPCi5eHanrLCOeH0ar5'); //测试key
\Pingpp\Pingpp::setApiKey('sk_live_GWD8WLDqbTOSqb9er5W9CGi5'); //真实key
$channel = strtolower("wx_pub");
$extra = array('open_id' => $t_openid);

try {
    $ch = \Pingpp\Charge::create(
        array(
            'subject'   => '2015中国企业家年会'.$subject,
            'body'      => $t_name.':'.$t_phone.':'.$t_address,
            'amount'    => $amount,
            'order_no'  => $orderNo,
            'currency'  => 'cny',
            'extra'     => $extra,
            'channel'   => $channel,
            'client_ip' => $_SERVER['REMOTE_ADDR'],
            'app'       => array('id' => 'app_90iv9CinvL40yDWT'),
Example #24
0
<?php

/* *
 * Ping++ Server SDK
 * 说明:
 * 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写, 并非一定要使用该代码。
 * 该代码仅供学习和研究 Ping++ SDK 使用,只是提供一个参考。
*/
require_once dirname(__FILE__) . '/../init.php';
/*
 * To set your key
 * key:the livekey or testkey from your app message from pingpp on the dashboard
 */
\Pingpp\Pingpp::setApiKey('sk_test_ibbTe5jLGCi5rzfH4OqPW9KC');
try {
    /*
     * To Create RedEnvelope
     */
    $red = \Pingpp\RedEnvelope::create(array('subject' => 'Your Subject', 'body' => 'Your Body', 'amount' => 100, 'order_no' => '1234567890', 'currency' => 'cny', 'extra' => array('nick_name' => 'Nick Name', 'send_name' => 'Send Name'), 'recipient' => 'Openid', 'channel' => 'wx_pub', 'app' => array('id' => 'app_1Gqj58ynP0mHeX1q'), 'description' => 'Your Description'));
    echo $red;
} catch (\Pingpp\Error\Base $e) {
    header('Status: ' . $e->getHttpStatus());
    echo $e->getHttpBody();
}
<?php

require dirname(__FILE__) . '/../init.php';
// api_key 获取方式:登录 [Dashboard](https://dashboard.pingxx.com)->点击管理平台右上角公司名称->开发信息-> Secret Key
$api_key = 'sk_test_ibbTe5jLGCi5rzfH4OqPW9KC';
// app_id 获取方式:登录 [Dashboard](https://dashboard.pingxx.com)->点击你创建的应用->应用首页->应用 ID(App ID)
$app_id = 'app_1Gqj58ynP0mHeX1q';
// 设置 API Key
\Pingpp\Pingpp::setApiKey($api_key);
// 设置私钥
\Pingpp\Pingpp::setPrivateKeyPath(__DIR__ . '/your_rsa_private_key.pem');
// 调用身份证认证接口
try {
    $result = \Pingpp\Identification::identify(array('type' => 'id_card', 'app' => $app_id, 'data' => array('id_name' => '张三', 'id_number' => '310181198910107641')));
    echo $result;
} catch (\Pingpp\Error\Base $e) {
    echo $e->getMessage();
}
// 调用银行卡认证接口
try {
    $result = \Pingpp\Identification::identify(array('type' => 'bank_card', 'app' => $app_id, 'data' => array('id_name' => '张三', 'id_number' => '310181198910107641', 'card_number' => '6201111122223333', 'phone_number' => '18623234545')));
    echo $result;
} catch (\Pingpp\Error\Base $e) {
    echo $e->getMessage();
}