예제 #1
0
 /**
  * 设置订单
  */
 public function setOrder(Order $order)
 {
     if (null !== $order) {
         try {
             $order->checkParams();
         } catch (Exception $e) {
             throw new PaymentException($e->getMessage());
         }
         if (!$order->hasParams('nonce_str')) {
             $order->nonce_str(Util::randomString());
         }
         if (!$order->hasParams('spbill_create_ip')) {
             $order->spbill_create_ip(Util::clientIP());
         }
         if (!$order->hasParams('trade_type')) {
             if (!$order->hasParams('openid')) {
                 throw new PaymentException('openid is required');
             }
             $order->trade_type('JSAPI');
         }
         $this->order = $order;
     }
 }