require_once './sdk/Hpp.Protocol.php'; require_once './sdk/Hpp.PayService.php'; require_once './repository.php'; //订单号 $orderNumber = md5(uniqid(mt_rand(), true)); //请求参数 $payRequest = new PayRequest(); $payRequest->setAppId('CA_APP-ID-0001'); $payRequest->setPayInterface($_POST['pay_interface']); $payRequest->setOrderNumber($orderNumber); $payRequest->setOrderSubject('php-demo-1分钱支付体验'); //订单标题 $payRequest->setOrderDescribe($_POST['order_describe']); $payRequest->setAmount($_POST['order_amount']); $payRequest->setCustomerIp('127.0.0.1'); $payRequest->setReturnUrl('http://127.0.0.1/callback-return.php?orderNumber' . $orderNumber); $payResponse = new PayResponse(PayService::startPay($payRequest)); //保存部分参数供后续用 //订单状态 $payRequest->setValue('status', Protocol::STATUS_ORDER_CREATED); $payRequest->setValue(Protocol::KEY_TRADE_SN, $payResponse->getTradeSn()); //相应数据 $payRequest->setValue('responseData', ['rawHtml' => $payResponse->getRawHtml(), 'wXQRPayUrl' => $payResponse->getWXQRPayUrl()]); //订单日期 $now = (new DateTime())->format('m-d H:i:s'); $payRequest->setValue('createOn', $now); Repository::save($payRequest->getOrderNumber(), $payRequest->toJsonString()); //ajax api输出 header('Content-Type: application/json; charset=UTF-8"'); echo json_encode(['orderNumber' => $orderNumber]);
/** * Service Call: Pay * @param PayRequest $payRequest * @return PayResponse * @throws APIException */ public function Pay($payRequest, $apiUsername = null) { $ret = new PayResponse(); $resp = $this->call("Pay", $payRequest, $apiUsername); $ret->init(PPUtils::nvpToMap($resp)); return $ret; }
/** * Service Call: Pay * @param PayRequest $payRequest * @param mixed $apiCredential - Optional API credential - can either be * a username configured in sdk_config.ini or a ICredential object * created dynamically * @return PayResponse * @throws APIException */ public function Pay($payRequest, $apiCredential = NULL) { $ret = new PayResponse(); $resp = $this->call('AdaptivePayments', 'Pay', $payRequest, $apiCredential); $ret->init(PPUtils::nvpToMap($resp)); return $ret; }
/** * Service Call: Pay * @param PayRequest $payRequest * @param mixed $apiCredential - Optional API credential - can either be * a username configured in sdk_config.ini or a ICredential object * created dynamically * @return PayResponse * @throws APIException */ public function Pay($payRequest, $apiCredential = NULL) { $apiContext = new PPApiContext($this->config); $handlers = array(new PPPlatformServiceHandler($apiCredential, self::$SDK_NAME, self::$SDK_VERSION)); $ret = new PayResponse(); $resp = $this->call('AdaptivePayments', 'Pay', $payRequest, $apiContext, $handlers); $ret->init(PPUtils::nvpToMap($resp)); return $ret; }
/** * Get the url to forward the customer to for completion of payment * * @param PayResponse $payResponse * @return string The URL to forward to */ public function getForwardPayUrl($payResponse) { return self::PAYSON_WWW_HOST . sprintf(self::PAYSON_WWW_PAY_FORWARD_URL, $payResponse->getToken()); }
<?php //--------------------------------------------------------- //财付通即时到帐支付应答(处理回调)示例,商户按照此文档进行开发即可 //--------------------------------------------------------- require_once "../classes/PayResponse.class.php"; require_once "tenpay_config.php"; /* 创建支付结果反馈响应对象:支付跳转接口为异步返回,用户在财付通完成支付后,财付通通过回调return_url和notify_url向财付通APP反馈支付结果。 */ $resHandler = new PayResponse($key); //获取通知id:支付结果通知id,支付成功返回通知id,要获取订单详细情况需用此ID调用通知验证接口。 echo "<br/>" . "本次支付的通知ID:" . $resHandler->getNotifyId() . "<br/>";
/** * Get the url to forward the customer to for completion of payment * * @param PayResponse $payResponse * @return string The URL to forward to */ public function getForwardPayUrl($payResponse) { return sprintf($this->protocol, $this->useTestEnvironment ? 'test-' : '') . self::PAYSON_WWW_HOST . sprintf(self::PAYSON_WWW_PAY_FORWARD_URL, $payResponse->getToken()); }