Esempio n. 1
0
 public function getRequestUrl($orderId, $returnUrl, $notifyUrl)
 {
     // 参数验证
     $validator = new Validator(array('orderId' => $orderId, 'returnUrl' => $returnUrl, 'notifyUrl' => $notifyUrl));
     $orderId = $validator->required()->digits()->min(1)->validate('orderId');
     $returnUrl = $validator->required()->validate('returnUrl');
     $notifyUrl = $validator->required()->validate('notifyUrl');
     $this->validate($validator);
     //设置订单 ID
     $this->orderId = $orderId;
     // 取得订单
     $orderBasicService = new OrderBasicService();
     $orderInfo = $orderBasicService->loadOrderInfoById($orderId);
     if (empty($orderInfo) || $orderInfo->isEmpty()) {
         throw new \InvalidArgumentException('invalid order_id [' . $orderId . ']');
     }
     $desc = $orderInfo['order_id'] . '|' . Money::toSmartyDisplay($orderInfo['order_amount']) . '|' . $orderInfo['system_id'] . '|WAP';
     // 构造要请求的参数数组,无需改动
     $parameterCreate = array("req_data" => '<direct_trade_create_req><subject>' . $desc . '</subject><out_trade_no>' . $orderInfo['order_sn'] . '_' . $orderInfo['order_id'] . '</out_trade_no><total_fee>' . Money::toDisplay($orderInfo['order_amount'], 2) . "</total_fee><seller_account_name>" . $this->account . "</seller_account_name><notify_url>" . $notifyUrl . "</notify_url><out_user>" . $orderInfo['user_id'] . "</out_user><merchant_url></merchant_url>" . "<call_back_url>" . $returnUrl . "</call_back_url></direct_trade_create_req>", "service" => $this->configServiceCreate, "sec_id" => $this->configSecId, "partner" => $this->partnerId, "req_id" => date("Ymdhms"), "format" => $this->configFormat, "v" => $this->configVersion);
     // 首先申请 Token
     $result = $this->callAlipayWapGateway($this->buildRequestLinkData($parameterCreate));
     // 调用GetToken方法,并返回token
     $token = $this->getToken($result);
     if (!$token) {
         printLog($this->getGatewayType() . ' 获取 token 失败');
         return null;
     }
     // 构造要请求的参数数组,无需改动
     $parameterExecute = array("req_data" => "<auth_and_execute_req><request_token>" . $token . "</request_token></auth_and_execute_req>", "service" => $this->configServiceExecute, "sec_id" => $this->configSecId, "partner" => $this->partnerId, "call_back_url" => $returnUrl, "format" => $this->configFormat, "v" => $this->configVersion);
     return $this->configGateway . $this->buildRequestLinkData($parameterExecute);
 }
Esempio n. 2
0
 public function getRequestUrl($orderId, $returnUrl, $notifyUrl)
 {
     // 参数验证
     $validator = new Validator(array('orderId' => $orderId, 'returnUrl' => $returnUrl, 'notifyUrl' => $notifyUrl));
     $orderId = $validator->required()->digits()->min(1)->validate('orderId');
     $returnUrl = $validator->required()->validate('returnUrl');
     $notifyUrl = $validator->required()->validate('notifyUrl');
     $this->validate($validator);
     //设置订单 ID
     $this->orderId = $orderId;
     // 取得订单
     $orderBasicService = new OrderBasicService();
     $orderInfo = $orderBasicService->loadOrderInfoById($orderId);
     if (empty($orderInfo) || $orderInfo->isEmpty()) {
         throw new \InvalidArgumentException('invalid order_id [' . $orderId . ']');
     }
     $desc = $orderInfo['order_id'] . '|' . Money::toSmartyDisplay($orderInfo['order_amount']) . '|' . $orderInfo['system_id'];
     //构造要请求的参数数组,无需改动
     $parameter = array("service" => "create_direct_pay_by_user", "partner" => $this->partnerId, "payment_type" => 1, "notify_url" => $notifyUrl, "return_url" => $returnUrl, "seller_email" => $this->account, "out_trade_no" => $orderInfo['order_sn'] . '_' . $orderInfo['order_id'], "subject" => $desc, "total_fee" => Money::toDisplay($orderInfo['order_amount'], 2), "body" => $desc, "show_url" => '', "anti_phishing_key" => '', "exter_invoke_ip" => '', "_input_charset" => 'utf-8');
     //建立请求
     $alipaySubmit = new AlipaySubmit($this->alipayConfig);
     return $alipaySubmit->buildRequestUrl($parameter);
 }