CouponData.php 2.21 KB
<?php

/**
 * Created by PhpStorm.
 * User: Targaryen
 * Date: 2016/4/19
 * Time: 10:50
 */
namespace LibModels\Wap\Coupon;

use Api\Sign;
use Api\Yohobuy;

class CouponData
{

//    const API_URL = 'http://api.open.yohobuy.com/';

    /**
     * 获取领券楼层数据
     *
     * @param $uid 用户ID
     * @param $contentCode 资源码
     * @return array|mixed
     */
    public static function getCouponRousource($contentCode, $uid)
    {
        $param = self::param();
        $param['method'] = 'app.promotion.queryCouponCenter';
        $param['contentCode'] = $contentCode;
        if (!empty($uid) && $uid !== '' && $uid !== null) {
            $param['uid'] = $uid;
        }
        $param['client_secret'] = Sign::getSign($param);
        return Yohobuy::get(Yohobuy::API_URL, $param);
    }


    /**
     * @param $uid 用户ID
     * @param $couponId 优惠券ID
     * @return mixed
     */
    public static function receiveCoupon($uid, $couponId)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.promotion.getCoupon';
        $param['couponId'] = $couponId;
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);
        return Yohobuy::get(Yohobuy::API_URL, $param);
    }

    /**
     * 取得公共的参数
     *
     * @return array
     */
    public static function param()
    {
        $clientType = self::clientType();
        $param = array(
            'app_version' => '3.8.2',
            'client_type' => $clientType,
            'os_version' => 'yohobuy:h5',
            'private_key' => Yohobuy::$privateKeyList[$clientType],
            'screen_size' => '720x1280',
            'v' => '7',
        );
        return $param;
    }

    /**
     * 取得当前的客户端类型
     */
    public static function clientType()
    {
        // 苹果设备
        if (strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone')) {
            return 'iphone';
        }
        // 苹果IPAD
        elseif (strstr($_SERVER['HTTP_USER_AGENT'], 'iPad')) {
            return 'ipad';
        }
        elseif (stristr($_SERVER['HTTP_USER_AGENT'], 'android')) {
            return 'android';
        }
        // 其它
        else {
            return 'web';
        }
    }
}