CouponData.php
2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?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
{
// 需要同步更新 YOHOBUY 接口 线下调试调用线上接口时使用
// 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';
}
}
}