Example #1
0
 /**
  * 
  * 生成直接支付url,支付url有效期为2小时,模式二
  * @param UnifiedOrderInput $input
  */
 public function GetPayUrl($input)
 {
     if ($input->GetTrade_type() == "NATIVE") {
         $result = Api::unifiedOrder($input);
         return $result;
     }
 }
Example #2
0
 /**
  * 
  * 获取jsapi支付的参数
  * @param array $UnifiedOrderResult 统一支付接口返回的数据
  * @throws Exception
  * 
  * @return json数据,可直接填入js函数作为参数
  */
 public function GetJsApiParameters($UnifiedOrderResult)
 {
     if (!array_key_exists("appid", $UnifiedOrderResult) || !array_key_exists("prepay_id", $UnifiedOrderResult) || $UnifiedOrderResult['prepay_id'] == "") {
         throw new Exception("参数错误");
     }
     $jsapi = new LibJsApiPay();
     $jsapi->SetAppid($UnifiedOrderResult["appid"]);
     $timeStamp = time();
     $jsapi->SetTimeStamp("{$timeStamp}");
     $jsapi->SetNonceStr(Api::getNonceStr());
     $jsapi->SetPackage("prepay_id=" . $UnifiedOrderResult['prepay_id']);
     $jsapi->SetSignType("MD5");
     $jsapi->SetPaySign($jsapi->MakeSign());
     $parameters = json_encode($jsapi->GetValues());
     return $parameters;
 }
Example #3
0
 /**
  * 
  * 撤销订单,如果失败会重复调用10次
  * @param string $out_trade_no
  * @param 调用深度 $depth
  */
 public function cancel($out_trade_no, $depth = 0)
 {
     if ($depth > 10) {
         return false;
     }
     $clostOrder = new Reverse();
     $clostOrder->SetOut_trade_no($out_trade_no);
     $result = Api::reverse($clostOrder);
     //接口调用失败
     if ($result["return_code"] != "SUCCESS") {
         return false;
     }
     //如果结果为success且不需要重新调用撤销,则表示撤销成功
     if ($result["result_code"] != "SUCCESS" && $result["recall"] == "N") {
         return true;
     } else {
         if ($result["recall"] == "Y") {
             return $this->cancel($out_trade_no, ++$depth);
         }
     }
     return false;
 }