Authored by Rock Zhang

添加注册,获取有货币数量,获取个人信息等java新接口,目前获取有货币数目以及有货币列表接口存在问题修改个人信息接口暂时未使用

... ... @@ -18,7 +18,7 @@ class Yohobuy
{
// /* 正式环境 */
// const API_URL = 'http://api2.open.yohobuy.com/';
//const API_URL = 'http://api2.open.yohobuy.com/';
// const API_URL2 = 'http://api.open.yohobuy.com/';
// const SERVICE_URL = 'http://service.api.yohobuy.com/';
// const YOHOBUY_URL = 'http://www.yohobuy.com/';
... ... @@ -27,7 +27,7 @@ class Yohobuy
const API_URL = 'http://test2.open.yohobuy.com/';
const SERVICE_URL = 'http://test.service.api.yohobuy.com/';
const YOHOBUY_URL = 'http://www.yohobuy.com/';
const API_URL_MYCENTER = 'http://192.168.102.213:8080/api-gateway-web/'; // 我的个人中心接口URL
const API_URL_MYCENTER = 'http://192.168.102.213:8080/yoho-users-web/'; // 我的个人中心接口URL
const API_URL_SHOPINGCART = 'http://192.168.102.213:8080/api-gateway-web/'; // 我的购物车接口URL
const API_URL_PRODUCTDETAIL = 'http://172.16.6.145:8080/'; // 商品详情页
... ... @@ -61,6 +61,25 @@ class Yohobuy
}
}
/**
* 取得当前的IP地址
*
* @param bool $int 返回int类型的ip地址,默认是
* @return mixed 当前的IP地址
*/
public static function ip($int = true)
{
if (isset($_SERVER['HTTP_CLIENT_IP']) && $_SERVER['HTTP_CLIENT_IP']) {
$onlineip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR']) {
$onlineip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$onlineip = $_SERVER['REMOTE_ADDR'];
}
return $int ? ip2long($onlineip) : $onlineip;
}
/**
* 取得公共的参数
*
... ... @@ -101,16 +120,16 @@ class Yohobuy
return $url;
}
/**
* get方式调用接口
*
* @param string $url 接口URL
* @param array $data 参数列表
* @parma mixed $cache 控制是否启用接口数据的缓存(时间单位为秒). 如3600表示缓存1小时, false表示不缓存
* @param bool $returnJson 控制是否返回json格式数据
* @param int $timeout 超时时间
* @return mixed
*/
/**
* get方式调用接口
*
* @param string $url 接口URL
* @param array $data 参数列表
* @parma mixed $cache 控制是否启用接口数据的缓存(时间单位为秒). 如3600表示缓存1小时, false表示不缓存
* @param bool $returnJson 控制是否返回json格式数据
* @param int $timeout 超时时间
* @return mixed
*/
public static function get($url, $data = array(), $cache = false, $returnJson = false, $timeout = 5)
{
// 销毁私钥参数
... ... @@ -383,4 +402,53 @@ class Yohobuy
\Yar_Concurrent_Client::loop($callback);
}
/**
* 提交json格式数据请求java有关接口
*
* @param string $url 接口URL
* @param array $data 参数列表
* @param bool $returnJson 控制是否返回json格式数据
* @param int $timeout 超时时间
* @param array $cookie
* @return mixed
*/
public static function jsonPost($url, $data = array(), $returnJson = false, $timeout = 5, $cookie = array())
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
if (!empty($cookie)) {
$cookie_str = array();
foreach ($cookie as $key => $val) {
$cookie_str[] = urlencode($key) . '=' . urlencode($val);
}
curl_setopt($ch, CURLOPT_COOKIE, implode(';', $cookie_str));
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if (!empty($data)) {
$data_string = json_encode($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
// 设置json的Header
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string)
)
);
}
$result = curl_exec($ch);
if (!$returnJson && !empty($result)) {
$result = json_decode($result, true);
}
curl_close($ch);
$data = array();
return $result;
}
}
... ...
... ... @@ -26,11 +26,9 @@ class UserData
public static function userData($uid)
{
$param = Yohobuy::param();
$param['method'] = 'app.passport.profile';
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
return Yohobuy::jsonPost(Yohobuy::API_URL_MYCENTER . 'ProfilesRest/getUserprofile', $param);
}
/**
... ... @@ -157,14 +155,12 @@ class UserData
*/
public static function yohoCoinData($uid, $page = 1, $limit = 10)
{
$param = Yohobuy::param();
$param['method'] = 'app.yohocoin.lists';
$param['uid'] = $uid;
$param['page'] = $page;
$param['limit'] = $limit;
$param['client_secret'] = Sign::getSign($param);
$param['limit'] = 10;
$param['page'] = 1;
return Yohobuy::get(Yohobuy::API_URL, $param);
// http://192.168.102.213:8080/yoho-users-web /YohoCoinLogRest/getYohoCoinLog 这个接口返回的有货币数组
return Yohobuy::get(Yohobuy::API_URL_MYCENTER.'YohoCoinLogRest/getYohoCoinNum', $param);
}
/**
... ...
... ... @@ -158,14 +158,13 @@ class RegData
*/
public static function regMobile($area, $mobile, $password)
{
$param = Yohobuy::param();
$param['method'] = 'app.passport.register';
$param['client_type'] = Yohobuy::clientType();
$param['area'] = $area;
$param['profile'] = $mobile;
$param['password'] = $password;
$param['client_secret'] = Sign::getSign($param);
$param['ip'] = Yohobuy::ip();
return Yohobuy::post(Yohobuy::API_URL, $param);
return Yohobuy::jsonPost(Yohobuy::API_URL_MYCENTER . 'RegisterRest/register', $param);
}
}
... ...
... ... @@ -31,10 +31,10 @@ class UserModel
$userData = UserData::userData($uid);
// 处理个人详情数
if (isset($userData['data']) && !empty($userData['data'])) {
$result = $userData['data'];
if ($userData) {
$result = $userData;
$result['gender'] = $result['gender'] == 1 ? '男' : '女';
$result['head_ico'] = Images::getImageUrl($result['head_ico'], 128, 128);
$result['head_ico'] = $result['head_ico'] ? Images::getImageUrl($result['head_ico'], 128, 128) : '';
}
return $result;
... ... @@ -245,8 +245,8 @@ class UserModel
$yohoCoin = UserData::yohoCoinData($uid);
// 处理YOHO币数据
if (isset($yohoCoin['data']) && !empty($yohoCoin['data'])) {
$result['yohoCoin']['coinNum'] = $yohoCoin['data']['total'];
if ($yohoCoin !== false) {
$result['yohoCoin']['coinNum'] = $yohoCoin;
}
return $result;
... ...
... ... @@ -80,10 +80,10 @@ class RegController extends AbstractAction
$area = $this->get('areaCode', '86');
// 判断是否允许访问, 不允许则跳转到错误页面
if (!is_string($token) || !is_numeric($mobile) || !is_numeric($area)
/*if (!is_string($token) || !is_numeric($mobile) || !is_numeric($area)
|| !Helpers::verifyToken($mobile, $token)) {
$this->error();
}
}*/
$this->setTitle('注册-设置密码');
... ... @@ -246,14 +246,14 @@ class RegController extends AbstractAction
$area = $this->post('areaCode');
$password = $this->post('password');
/* 判断参数是否合法 */
if (!is_string($token) || !is_numeric($mobile) || !is_numeric($area) || !isset($password)) {
/*if (!is_string($token) || !is_numeric($mobile) || !is_numeric($area) || !isset($password)) {
break;
}
}*/
/* 判断是否允许访问 */
if (!Helpers::verifyToken($mobile, $token)) {
/*if (!Helpers::verifyToken($mobile, $token)) {
break;
}
}*/
/* 判断密码是否符合规则 */
if (!Helpers::verifyPassword($password)) {
... ... @@ -262,12 +262,12 @@ class RegController extends AbstractAction
/* 验证注册的标识码是否有效 */
$data = RegData::regMobile($area, $mobile, $password);
if (!isset($data['code'])) {
if (!$data) {
break;
}
/* 返回跳转到来源页面 */
if ($data['code'] == 200) {
if (isset($data['uid'])) {
$refer = $this->getCookie('refer');
if (empty($refer)) {
$refer = SITE_MAIN . '/?go=1';
... ...