Authored by 梁志锋

Merge remote-tracking branch 'remotes/origin/hotfix/unionTrans'

... ... @@ -165,12 +165,14 @@ class Yohobuy
*
* @param string $url 接口URL
* @param array $data 参数列表
* @parma mixed $cache 控制是否启用接口数据的缓存(时间单位为秒). 如3600表示缓存1小时, false表示不缓存
* @param bool $cache 控制是否启用接口数据的缓存(时间单位为秒). 如3600表示缓存1小时, false表示不缓存
* @param bool $returnJson 控制是否返回json格式数据
* @param int $timeout 超时时间
* @param null $userAgent
* @param bool $useGzip 是否启用Gzip
* @return mixed
*/
public static function get($url, $data = array(), $cache = false, $returnJson = false, $timeout = 5, $userAgent = null)
public static function get($url, $data = array(), $cache = false, $returnJson = false, $timeout = 5, $userAgent = null, $useGzip = true)
{
// 销毁私钥参数
if (isset($data['private_key'])) {
... ... @@ -191,6 +193,10 @@ class Yohobuy
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($useGzip) {
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
}
if (!empty($userAgent)) {
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
}
... ...
... ... @@ -360,9 +360,10 @@ class CartData
* @param string $couponCode 优惠券码
* @param mixed $yohoCoin 使用的YOHO币数量或为空
* @param string $skuList 购买限购商品时需要传递的参数
* @param string|null $userAgent 联盟过来用户下单时需要的User-Agent信息
* @return array 接口返回的数据
*/
public static function orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin, $skuList)
public static function orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin, $skuList, $userAgent)
{
$param = Yohobuy::param();
$param['debug'] = 'Y';
... ... @@ -398,7 +399,7 @@ class CartData
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
return Yohobuy::get(Yohobuy::API_URL, $param, false, false, 5, $userAgent);
}
/**
... ...
... ... @@ -628,9 +628,10 @@ class CartModel
* @param string $couponCode 优惠券码
* @param mixed $yohoCoin 使用的YOHO币数量或为空
* @param string $skuList 购买限购商品时需要传递的参数
* @param string|null $userAgent 联盟过来用户下单时需要的User-Agent信息
* @return array 接口返回的数据
*/
public static function orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin, $skuList)
public static function orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin, $skuList, $userAgent = null)
{
$result = array('code' => 400, 'message' => '出错啦');
... ... @@ -644,7 +645,7 @@ class CartModel
$result['code'] = 403;
$result['message'] = '请选择配送方式';
} else {
$orderSubRes = CartData::orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin, $skuList);
$orderSubRes = CartData::orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin, $skuList, $userAgent);
if ($orderSubRes && isset($orderSubRes['code'])) {
$result = $orderSubRes;
}
... ...
<?php
use Action\AbstractAction;
use Hood\Core\Security\AuthCode;
use Index\CartModel;
use Index\UserModel;
use Plugin\Helpers;
... ... @@ -445,7 +446,19 @@ class IndexController extends AbstractAction
$couponCode = $this->post('couponCode', null);
$yohoCoin = $this->post('yohoCoin', 1);
$skuList = $this->post('skuList', '');
$result = CartModel::orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin, $skuList);
/* 判断是否是友盟过来的用户 */
$userAgent = null;
if (!empty($_COOKIE['_QYH_UNION'])) {
/* 解密客户端联盟信息 */
$unionKey = AuthCode::decode($_COOKIE['_QYH_UNION'], 'q_union_yohobuy');
/* 检查联盟参数是否有效 */
$unionInfo = empty($unionKey) ? array() : json_decode($unionKey, true);
/* 模拟APP的User-Agent */
$userAgent = isset($unionInfo['client_id']) ? 'YOHO!Buy/3.8.2.259(Model/PC;Channel/' . $unionInfo['client_id'] . ';uid/' . $uid . ')' : null;
}
$result = CartModel::orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin, $skuList, $userAgent);
// 记录下单异常的数据
if (empty($result)) {
... ... @@ -462,13 +475,13 @@ class IndexController extends AbstractAction
$this->echoJson($result);
}
if ($uid && !empty($result['data'])) {
/*if ($uid && !empty($result['data'])) {
try {
UnionTrans::set($uid, $result['data']['order_code'], $result['data']['order_amount']);
} catch (Exception $e) {
// do nothing
}
}
}*/
} else {
echo ' ';
}
... ...