public function unifiedorder($openId, $product_id, $data) { //统一下单 $input = new UnifiedOrder(); $input->SetBody($data['body']); if (isset($data['attach'])) { $input->SetAttach($data['attach']); } $input->SetOut_trade_no($data['out_trade_no']); $input->SetTotal_fee($data['total_fee']); if (isset($data['time_start'])) { $input->SetTime_start($data['time_start']); } if (isset($data['time_expire'])) { $input->SetTime_expire($data['time_expire']); } if (isset($data['goods_tag'])) { $input->SetGoods_tag($data['goods_tag']); } if (isset($data['notify_url'])) { $input->SetNotify_url($data['notify_url']); } if (isset($data['spbill_create_ip'])) { $input->SetSpbill_create_ip($data['spbill_create_ip']); } $input->SetTrade_type('NATIVE'); $input->SetOpenid($openId); $input->SetProduct_id($product_id); $result = Api::unifiedOrder($input); return $result; }
public function Queryorder($transaction_id) { $input = new OrderQuery(); $input->SetTransaction_id($transaction_id); $result = Api::orderQuery($input); if (array_key_exists("return_code", $result) && array_key_exists("result_code", $result) && $result["return_code"] == "SUCCESS" && $result["result_code"] == "SUCCESS") { return true; } return false; }
public function createOrder($data) { if (!isset($data['body']) || empty($data['body'])) { throw new Exception('商品描述缺少'); } if (!isset($data['out_trade_no']) || empty($data['out_trade_no'])) { throw new Exception('商户订单号缺少'); } if (!isset($data['total_fee']) || empty($data['total_fee'])) { throw new Exception('总金额缺少'); } $input = new UnifiedOrder(); $input->SetBody($data['body']); if (isset($data['attach'])) { $input->SetAttach($data['attach']); } $input->SetOut_trade_no($data['out_trade_no']); $input->SetTotal_fee($data['total_fee']); if (isset($data['time_start'])) { $input->SetTime_start($data['time_start']); } if (isset($data['time_expire'])) { $input->SetTime_expire($data['time_expire']); } if (isset($data['goods_tag'])) { $input->SetGoods_tag($data['goods_tag']); } if (isset($data['notify_url'])) { $input->SetNotify_url($data['notify_url']); } if (isset($data['spbill_create_ip'])) { $input->SetSpbill_create_ip($data['spbill_create_ip']); } $input->SetTrade_type('JSAPI'); if (isset($data['product_id'])) { $input->SetProduct_id($data['product_id']); } if (isset($data['openid'])) { $input->SetOpenid($data['openid']); } $order = Api::unifiedOrder($input); $jsApiParameters = $this->GetJsApiParameters($order); //返回JSAPI信息 return $jsApiParameters; }
/** * * 生成直接支付url,支付url有效期为2小时,模式二 * @param Array $data */ private function getPayUrl(array $data) { if (!isset($data['body']) || empty($data['body'])) { throw new Exception('商品描述缺少'); } if (!isset($data['out_trade_no']) || empty($data['out_trade_no'])) { throw new Exception('商户订单号缺少'); } if (!isset($data['total_fee']) || empty($data['total_fee'])) { throw new Exception('总金额缺少'); } // // APP和网页支付提交用户端ip,Native支付填调用微信支付API的机器IP。 // if (!isset($data['spbill_create_ip']) || empty($data['spbill_create_ip'])) { // throw new Exception('终端IP缺少'); // } $input = new UnifiedOrder(); $input->SetBody($data['body']); if (isset($data['attach'])) { $input->SetAttach($data['attach']); } $input->SetOut_trade_no($data['out_trade_no']); $input->SetTotal_fee($data['total_fee']); //单位分 if (isset($data['time_start'])) { $input->SetTime_start($data['time_start']); } if (isset($data['time_expire'])) { $input->SetTime_expire($data['time_expire']); } if (isset($data['goods_tag'])) { $input->SetGoods_tag($data['goods_tag']); } if (isset($data['notify_url'])) { $input->SetNotify_url($data['notify_url']); } if (isset($data['spbill_create_ip'])) { $input->SetSpbill_create_ip($data['spbill_create_ip']); } $input->SetTrade_type('NATIVE'); $input->SetProduct_id($data['product_id']); $result = Api::unifiedOrder($input); return $result['code_url']; }
/** * * 撤销订单,如果失败会重复调用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; }