Showing
30 changed files
with
2355 additions
and
35 deletions
1 | <?php | 1 | <?php |
2 | +namespace LibModels\Wap\Category; | ||
2 | 3 | ||
3 | -/* | ||
4 | - * To change this license header, choose License Headers in Project Properties. | ||
5 | - * To change this template file, choose Tools | Templates | ||
6 | - * and open the template in the editor. | 4 | +use Api\Yohobuy; |
5 | +use Api\Sign; | ||
6 | + | ||
7 | +/** | ||
8 | + * 品牌数据接口操作类 | ||
9 | + * | ||
10 | + * @name BrandData | ||
11 | + * @package Library/LibModels/wap/Category | ||
12 | + * @copyright yoho.inc | ||
13 | + * @version 1.0 (2015-10-10) | ||
14 | + * @author gtskk <rocky.zhang@yoho.cn> | ||
7 | */ | 15 | */ |
16 | +class BrandData | ||
17 | +{ | ||
18 | + /** | ||
19 | + * 获取品牌数据 | ||
20 | + * | ||
21 | + * @param integer $channel 是否,默认1表示是,传值为空是app中用于品牌搜索的数据 | ||
22 | + * | ||
23 | + * @return array 品牌数据 | ||
24 | + */ | ||
25 | + public static function getBrandsData($channel = 1) | ||
26 | + { | ||
27 | + // 构建必传参数 | ||
28 | + $param = Yohobuy::param(); | ||
29 | + | ||
30 | + $param['method'] = 'app.brand.brandlist'; | ||
31 | + $param['yh_channel'] = $channel; | ||
32 | + $param['client_secret'] = Sign::getSign($param); | ||
33 | + | ||
34 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
35 | + } | ||
36 | + | ||
37 | + /** | ||
38 | + * 获取品牌页顶部楼层数据 | ||
39 | + * | ||
40 | + * @return array 品牌也顶部楼层数据 | ||
41 | + */ | ||
42 | + public static function getBrandTopData() | ||
43 | + { | ||
44 | + // 构建必传参数 | ||
45 | + $param = Yohobuy::param(); | ||
8 | 46 | ||
47 | + $param['content_code'] = 'ce6ac059493ec26241a8cbe0bfa1b17a'; | ||
48 | + $param['client_secret'] = Sign::getSign($param); | ||
49 | + | ||
50 | + return Yohobuy::get(Yohobuy::SERVICE_URL.'operations/api/v5/resource/get', $param); | ||
51 | + } | ||
52 | +} |
1 | <?php | 1 | <?php |
2 | +namespace LibModels\Wap\Category; | ||
2 | 3 | ||
3 | -/* | ||
4 | - * To change this license header, choose License Headers in Project Properties. | ||
5 | - * To change this template file, choose Tools | Templates | ||
6 | - * and open the template in the editor. | 4 | +use Api\Yohobuy; |
5 | +use Api\Sign; | ||
6 | + | ||
7 | +/** | ||
8 | + * 品类数据接口操作类 | ||
9 | + * | ||
10 | + * @name ClassData | ||
11 | + * @package Library/LibModels/wap/Category | ||
12 | + * @copyright yoho.inc | ||
13 | + * @version 1.0 (2015-10-10) | ||
14 | + * @author gtskk <rocky.zhang@yoho.cn> | ||
7 | */ | 15 | */ |
16 | +class ClassData | ||
17 | +{ | ||
18 | + /** | ||
19 | + * 获取品类数据 | ||
20 | + * | ||
21 | + * @return array 品类数据 | ||
22 | + */ | ||
23 | + public static function getClassesData() | ||
24 | + { | ||
25 | + // 构建必传参数 | ||
26 | + $param = Yohobuy::param(); | ||
8 | 27 | ||
28 | + $param['method'] = 'app.sort.get'; | ||
29 | + $param['client_secret'] = Sign::getSign($param); | ||
30 | + | ||
31 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
32 | + } | ||
33 | +} |
1 | <?php | 1 | <?php |
2 | +namespace LibModels\Wap\Category; | ||
2 | 3 | ||
3 | -/* | ||
4 | - * To change this license header, choose License Headers in Project Properties. | ||
5 | - * To change this template file, choose Tools | Templates | ||
6 | - * and open the template in the editor. | 4 | +use Api\Yohobuy; |
5 | +use Api\Sign; | ||
6 | + | ||
7 | +/** | ||
8 | + * 关注数据接口操作类 | ||
9 | + * | ||
10 | + * @name FocusData | ||
11 | + * @package Library/LibModels/wap/Category | ||
12 | + * @copyright yoho.inc | ||
13 | + * @version 1.0 (2015-10-10) | ||
14 | + * @author gtskk <rocky.zhang@yoho.cn> | ||
7 | */ | 15 | */ |
16 | +class FocusData | ||
17 | +{ | ||
18 | + /** | ||
19 | + * 获取关注数据 | ||
20 | + * | ||
21 | + * @param integ $uid 用户ID | ||
22 | + * @param string $gender 性别 | ||
23 | + * @param integer $limit 读取数目限制,默认为10 | ||
24 | + * @param integer $page 读取分页限制,默认为1 | ||
25 | + * @return array 关注数据 | ||
26 | + */ | ||
27 | + public static function getFocusData($uid, $gender, $limit = 10, $page = 1) | ||
28 | + { | ||
29 | + // 构建必传参数 | ||
30 | + $param = Yohobuy::param(); | ||
31 | + $param['uid'] = $uid; | ||
32 | + $param['gender'] = $gender; | ||
33 | + $param['limit'] = $limit; | ||
34 | + $param['page'] = $page; | ||
8 | 35 | ||
36 | + $param['client_secret'] = Sign::getSign($param); | ||
37 | + | ||
38 | + return Yohobuy::get(Yohobuy::SERVICE_URL.'guang/api/v1/attention/getlist', $param); | ||
39 | + } | ||
40 | +} |
1 | <?php | 1 | <?php |
2 | +namespace LibModels\Wap\Passport; | ||
2 | 3 | ||
3 | -/* | ||
4 | - * To change this license header, choose License Headers in Project Properties. | ||
5 | - * To change this template file, choose Tools | Templates | ||
6 | - * and open the template in the editor. | 4 | +use Api\Yohobuy; |
5 | +use Api\Sign; | ||
6 | + | ||
7 | +/** | ||
8 | + * 品类数据接口操作类 | ||
9 | + * | ||
10 | + * @name ClassData | ||
11 | + * @package Library/LibModels/wap/Category | ||
12 | + * @copyright yoho.inc | ||
13 | + * @version 1.0 (2015-10-10) | ||
14 | + * @author gtskk <rocky.zhang@yoho.cn> | ||
7 | */ | 15 | */ |
16 | +class ClassData | ||
17 | +{ | ||
18 | + /** | ||
19 | + * 获取地区数据 | ||
20 | + * | ||
21 | + * @return array 地区数据 | ||
22 | + */ | ||
23 | + public static function getAreasData() | ||
24 | + { | ||
25 | + // 构建必传参数 | ||
26 | + $param = Yohobuy::param(); | ||
27 | + | ||
28 | + $param['method'] = 'app.passport.getArea'; | ||
29 | + $param['client_secret'] = Sign::getSign($param); | ||
30 | + | ||
31 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
32 | + } | ||
33 | + | ||
34 | + /** | ||
35 | + * 通过手机号发送验证码找回密码 | ||
36 | + * | ||
37 | + * @param string $mobile 手机号 | ||
38 | + * @param integer $area 地区码ID | ||
39 | + * @return array 返回状态数据 | ||
40 | + */ | ||
41 | + public static function sendCodeToMobile($mobile, $area = 86) | ||
42 | + { | ||
43 | + // 构建必传参数 | ||
44 | + $param = Yohobuy::param(); | ||
8 | 45 | ||
46 | + $param['mobile'] = $mobile; | ||
47 | + $param['method'] = 'app.register.sendBackpwdCodeToMobile'; | ||
48 | + $param['client_secret'] = Sign::getSign($param); | ||
49 | + | ||
50 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
51 | + } | ||
52 | +} |
library/Plugin/Partner/Factory.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace Plugin\Partner; | ||
4 | + | ||
5 | +isset($_SESSION) || session_start(); | ||
6 | +defined('DS') || define('DS', '/'); | ||
7 | + | ||
8 | +/** | ||
9 | + * 抽象类: 第三方接口都会继承该类 | ||
10 | + * | ||
11 | + * @name Factory | ||
12 | + * @package library/Plugin/Partner | ||
13 | + * @copyright yoho.inc | ||
14 | + * @version 1.0 (2015-10-10 17:11:10) | ||
15 | + * @author fei.hong <fei.hong@yoho.cn> | ||
16 | + */ | ||
17 | +abstract class Factory | ||
18 | +{ | ||
19 | + /** | ||
20 | + * 接口名称 | ||
21 | + * | ||
22 | + * @var string | ||
23 | + */ | ||
24 | + protected $apiName = ''; | ||
25 | + /** | ||
26 | + * 接口配置 | ||
27 | + * | ||
28 | + * @var array | ||
29 | + */ | ||
30 | + protected $apiConfig = array(); | ||
31 | + /** | ||
32 | + * 接口对象 | ||
33 | + * | ||
34 | + * @var array | ||
35 | + */ | ||
36 | + protected static $apiObjs = array(); | ||
37 | + | ||
38 | + /** | ||
39 | + * 单例模式: 实例化需要调用的接口对象 | ||
40 | + * | ||
41 | + * @param string $apiName 接口名称 | ||
42 | + * @return object | ||
43 | + */ | ||
44 | + public static function create($apiName) | ||
45 | + { | ||
46 | + $apiName = strtolower($apiName); | ||
47 | + | ||
48 | + if (!isset(self::$apiObjs[$apiName])) | ||
49 | + { | ||
50 | + // require dirname(__FILE__) . DS . $apiName . DS . 'Call.class.php'; | ||
51 | + | ||
52 | + $apiNameCase = ucfirst($apiName); | ||
53 | + $apiClass = "Plugin\Partner\\{$apiNameCase}\\Call"; | ||
54 | + | ||
55 | + self::$apiObjs[$apiName] = new $apiClass(); | ||
56 | + self::$apiObjs[$apiName]->apiName = $apiName; | ||
57 | + self::$apiObjs[$apiName]->configure(); | ||
58 | + self::$apiObjs[$apiName]->init(); | ||
59 | + } | ||
60 | + | ||
61 | + return self::$apiObjs[$apiName]; | ||
62 | + } | ||
63 | + | ||
64 | + /** | ||
65 | + * 应用的配置 | ||
66 | + * | ||
67 | + * @return void | ||
68 | + */ | ||
69 | + protected function configure() | ||
70 | + { | ||
71 | + $this->apiConfig = require(dirname(__FILE__) . DS . $this->apiName . DS . 'Config.inc.php'); | ||
72 | + } | ||
73 | + | ||
74 | + /**初始化*/ | ||
75 | + abstract protected function init(); | ||
76 | + | ||
77 | + /**获取接口*/ | ||
78 | + abstract public function getAuthorizeUrl(); | ||
79 | + abstract public function getAccessToken(); | ||
80 | + abstract public function getUserInfo($token); | ||
81 | + abstract public function getFriends($token, $params); | ||
82 | + | ||
83 | + /**同步分享*/ | ||
84 | + abstract public function syncShare($token, $content, $image, $link); | ||
85 | +} |
library/Plugin/Partner/alipay/Call.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace Plugin\Partner\Alipay; | ||
4 | + | ||
5 | +use Plugin\Partner\Factory; | ||
6 | + | ||
7 | +define('TB_CLASS_PATH', dirname(__FILE__).'/class'); | ||
8 | +require TB_CLASS_PATH . '/lib/alipay.function.php'; | ||
9 | +require TB_CLASS_PATH . '/AlipaySubmit.class.php'; | ||
10 | +require TB_CLASS_PATH . '/AlipayNotify.class.php'; | ||
11 | + | ||
12 | +/** | ||
13 | + * 支付宝快捷的调用接口 | ||
14 | + * | ||
15 | + * @name Call | ||
16 | + * @package Plugin/Partner/alipay | ||
17 | + * @copyright yoho.inc | ||
18 | + * @version 1.0 (2015-10-10 17:56:42) | ||
19 | + * @author fei.hong <fei.hong@yoho.cn> | ||
20 | + */ | ||
21 | +class Call extends Factory | ||
22 | +{ | ||
23 | + protected $alipaySubmit; | ||
24 | + protected $alipayNotify; | ||
25 | + | ||
26 | + /** | ||
27 | + * 初始化 | ||
28 | + */ | ||
29 | + protected function init() | ||
30 | + { | ||
31 | + $this->alipaySubmit = new \AlipaySubmit($this->apiConfig); | ||
32 | + $this->alipayNotify = new \AlipayNotify($this->apiConfig); | ||
33 | + } | ||
34 | + | ||
35 | + /** | ||
36 | + * 获取授权URL | ||
37 | + * | ||
38 | + * @return string | ||
39 | + */ | ||
40 | + public function getAuthorizeUrl() | ||
41 | + { | ||
42 | + $parameter = array( | ||
43 | + 'service' => 'alipay.auth.authorize', | ||
44 | + 'partner' => $this->apiConfig['partner'], | ||
45 | + 'target_service' => 'user.auth.quick.login', | ||
46 | + 'return_url' => $this->apiConfig['return_url'], | ||
47 | + 'anti_phishing_key' => $this->alipaySubmit->query_timestamp(), | ||
48 | + 'exter_invoke_ip' => '', | ||
49 | + '_input_charset' => $this->apiConfig['input_charset'] | ||
50 | + ); | ||
51 | + | ||
52 | + echo '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>支付宝快捷登录</title></head><body>', | ||
53 | + $this->alipaySubmit->buildRequestForm($parameter, 'get'), | ||
54 | + '</body></html>'; | ||
55 | + exit(); | ||
56 | + } | ||
57 | + | ||
58 | + /** | ||
59 | + * 获取授权的TOKEN | ||
60 | + * | ||
61 | + * @return array | ||
62 | + */ | ||
63 | + public function getAccessToken() | ||
64 | + { | ||
65 | + $token = array(); | ||
66 | + | ||
67 | + $verify = $this->alipayNotify->verifyReturn(); | ||
68 | + if ($verify) | ||
69 | + { | ||
70 | + $token['access_token'] = isset($_GET['token']) ? $_GET['token'] : null; | ||
71 | + $token['user_id'] = isset($_GET['user_id']) ? $_GET['user_id'] : null; | ||
72 | + } | ||
73 | + | ||
74 | + return $token; | ||
75 | + } | ||
76 | + | ||
77 | + /** | ||
78 | + * 获取当前用户的基本资料 | ||
79 | + * | ||
80 | + * @param array $token 授权成功的TOKEN, 默认为NULL | ||
81 | + * @return array | ||
82 | + */ | ||
83 | + public function getUserInfo($token) | ||
84 | + { | ||
85 | + $parameter = array( | ||
86 | + '_input_charset' => $this->apiConfig['input_charset'], | ||
87 | + 'service' => 'mobile.common.login.userInfo.query', | ||
88 | + 'partner' => $this->apiConfig['partner'], | ||
89 | + 'token' => $token, | ||
90 | + 'timestamp' => date('Y-m-d H:i:s'), | ||
91 | + ); | ||
92 | + $result = $this->alipaySubmit->getUserInfoByToken($parameter, $token); | ||
93 | + | ||
94 | + return $result; | ||
95 | + } | ||
96 | + | ||
97 | + /** | ||
98 | + * 获取当前用户的偶像(关注)列表 | ||
99 | + * | ||
100 | + * 备注:此接口暂未开放 | ||
101 | + * | ||
102 | + * @param array $token 访问令牌 | ||
103 | + * @param array $params 参数列表 | ||
104 | + * @return array | ||
105 | + */ | ||
106 | + public function getFriends($token, $params) | ||
107 | + { | ||
108 | + return array(); | ||
109 | + } | ||
110 | + | ||
111 | + /** | ||
112 | + * 同步分享 | ||
113 | + * | ||
114 | + * 备注:此接口暂未开放 | ||
115 | + * | ||
116 | + * @param object $token 访问令牌 | ||
117 | + * @param String $image 新鲜事图片地址 | ||
118 | + * @param String $content 新鲜事主体内容 注意:最多200个字符。 | ||
119 | + * @param String $link 新鲜事标题和图片指向的链接 | ||
120 | + * @return Long 发布新鲜事的ID | ||
121 | + */ | ||
122 | + public function syncShare($token, $content, $image, $link) | ||
123 | + { | ||
124 | + return true; | ||
125 | + } | ||
126 | + | ||
127 | +} |
library/Plugin/Partner/alipay/Config.inc.php
0 → 100644
1 | +<?php | ||
2 | +defined('SITE_MAIN') || define('SITE_MAIN', $_SERVER['HTTP_HOST']); | ||
3 | + | ||
4 | +return array( | ||
5 | + // 合作身份者id,以2088开头的16位纯数字 | ||
6 | + 'partner' => '2088701661478015', | ||
7 | + // 安全检验码,以数字和字母组成的32位字符 | ||
8 | + 'key' => 'kcxawi9bb07mzh0aq2wcirsf9znusobw', | ||
9 | + // 签名方式,不需要修改 | ||
10 | + 'sign_type' => 'MD5', | ||
11 | + // 字符编码格式 目前支持 gbk 或 utf-8 | ||
12 | + 'input_charset' => 'utf-8', | ||
13 | + // ca证书路径地址,用于curl中ssl校验 (请保证cacert.pem文件在当前文件夹目录中) | ||
14 | + 'cacert' => dirname(__FILE__) .'/cacert.pem', | ||
15 | + // 访问模式,根据自己的服务器是否支持ssl访问,若支持请选择https;若不支持请选择http | ||
16 | + 'transport' => 'http', | ||
17 | + // 页面跳转同步通知页面路径 (需http://格式的完整路径,不允许加?id=123这类自定义参数) | ||
18 | + 'return_url' => SITE_MAIN . '/passport/sso/partnercallback/partner/alipay', | ||
19 | +); |
library/Plugin/Partner/alipay/cacert.pem
0 → 100644
This diff could not be displayed because it is too large.
1 | +<?php | ||
2 | +/** | ||
3 | + * 支付宝通知处理类 | ||
4 | + * | ||
5 | + * 调试通知返回时,可查看或改写log日志的写入TXT里的数据,来检查通知返回是否正常 | ||
6 | + * | ||
7 | + * @name AlipayNotify | ||
8 | + * @package lib/partner/alipay | ||
9 | + * @copyright yoho.inc | ||
10 | + * @version 5.0 (2014-03-06 16:41:20) | ||
11 | + * @author fei.hong <fei.hong@yoho.cn> | ||
12 | + */ | ||
13 | +class AlipayNotify { | ||
14 | + | ||
15 | + /** | ||
16 | + * HTTPS形式消息验证地址 | ||
17 | + */ | ||
18 | + var $https_verify_url = 'https://mapi.alipay.com/gateway.do?service=notify_verify&'; | ||
19 | + /** | ||
20 | + * HTTP形式消息验证地址 | ||
21 | + */ | ||
22 | + var $http_verify_url = 'http://notify.alipay.com/trade/notify_query.do?'; | ||
23 | + /** | ||
24 | + * 支付宝配置 | ||
25 | + */ | ||
26 | + var $alipay_config = array(); | ||
27 | + | ||
28 | + function __construct($alipay_config){ | ||
29 | + $this->alipay_config = $alipay_config; | ||
30 | + } | ||
31 | + | ||
32 | + function AlipayNotify($alipay_config) { | ||
33 | + $this->__construct($alipay_config); | ||
34 | + } | ||
35 | + | ||
36 | + /** | ||
37 | + * 针对notify_url验证消息是否是支付宝发出的合法消息 | ||
38 | + * @return 验证结果 | ||
39 | + */ | ||
40 | + function verifyNotify(){ | ||
41 | + if (empty($_POST)) { //判断POST来的数组是否为空 | ||
42 | + return false; | ||
43 | + } else { | ||
44 | + //生成签名结果 | ||
45 | + $isSign = $this->getSignVeryfy($_POST, $_POST["sign"]); | ||
46 | + //获取支付宝远程服务器ATN结果(验证是否是支付宝发来的消息) | ||
47 | + $responseTxt = 'true'; | ||
48 | + if (! empty($_POST["notify_id"])) {$responseTxt = $this->getResponse($_POST["notify_id"]);} | ||
49 | + | ||
50 | + //写日志记录 | ||
51 | + //if ($isSign) { | ||
52 | + // $isSignStr = 'true'; | ||
53 | + //} | ||
54 | + //else { | ||
55 | + // $isSignStr = 'false'; | ||
56 | + //} | ||
57 | + //$log_text = "responseTxt=".$responseTxt."\n notify_url_log:isSign=".$isSignStr.","; | ||
58 | + //$log_text = $log_text.createLinkString($_POST); | ||
59 | + //logResult($log_text); | ||
60 | + | ||
61 | + //验证 | ||
62 | + //$responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关 | ||
63 | + //isSign的结果不是true,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关 | ||
64 | + if (preg_match("/true$/i",$responseTxt) && $isSign) { | ||
65 | + return true; | ||
66 | + } else { | ||
67 | + return false; | ||
68 | + } | ||
69 | + } | ||
70 | + } | ||
71 | + | ||
72 | + /** | ||
73 | + * 针对return_url验证消息是否是支付宝发出的合法消息 | ||
74 | + * @return 验证结果 | ||
75 | + */ | ||
76 | + function verifyReturn(){ | ||
77 | + if(empty($_GET)) {//判断POST来的数组是否为空 | ||
78 | + return false; | ||
79 | + } | ||
80 | + else { | ||
81 | + //生成签名结果 | ||
82 | + $isSign = $this->getSignVeryfy($_GET, $_GET["sign"]); | ||
83 | + //获取支付宝远程服务器ATN结果(验证是否是支付宝发来的消息) | ||
84 | + $responseTxt = 'true'; | ||
85 | + if (! empty($_GET["notify_id"])) {$responseTxt = $this->getResponse($_GET["notify_id"]);} | ||
86 | + | ||
87 | + //写日志记录 | ||
88 | + //if ($isSign) { | ||
89 | + // $isSignStr = 'true'; | ||
90 | + //} | ||
91 | + //else { | ||
92 | + // $isSignStr = 'false'; | ||
93 | + //} | ||
94 | + //$log_text = "responseTxt=".$responseTxt."\n return_url_log:isSign=".$isSignStr.","; | ||
95 | + //$log_text = $log_text.createLinkString($_GET); | ||
96 | + //logResult($log_text); | ||
97 | + | ||
98 | + //验证 | ||
99 | + //$responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关 | ||
100 | + //isSign的结果不是true,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关 | ||
101 | + if (preg_match("/true$/i",$responseTxt) && $isSign) { | ||
102 | + return true; | ||
103 | + } else { | ||
104 | + return false; | ||
105 | + } | ||
106 | + } | ||
107 | + } | ||
108 | + | ||
109 | + /** | ||
110 | + * 获取返回时的签名验证结果 | ||
111 | + * @param $para_temp 通知返回来的参数数组 | ||
112 | + * @param $sign 返回的签名结果 | ||
113 | + * @return 签名验证结果 | ||
114 | + */ | ||
115 | + function getSignVeryfy($para_temp, $sign) { | ||
116 | + //除去待签名参数数组中的空值和签名参数 | ||
117 | + $para_filter = paraFilter($para_temp); | ||
118 | + | ||
119 | + //对待签名参数数组排序 | ||
120 | + $para_sort = argSort($para_filter); | ||
121 | + | ||
122 | + //把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串 | ||
123 | + $prestr = createLinkstring($para_sort); | ||
124 | + | ||
125 | + $isSgin = false; | ||
126 | + switch ($this->alipay_config['sign_type']) { | ||
127 | + case "MD5" : | ||
128 | + $isSgin = md5Verify($prestr, $sign, $this->alipay_config['key']); | ||
129 | + break; | ||
130 | + default : | ||
131 | + $isSgin = false; | ||
132 | + } | ||
133 | + | ||
134 | + return $isSgin; | ||
135 | + } | ||
136 | + | ||
137 | + /** | ||
138 | + * 获取远程服务器ATN结果,验证返回URL | ||
139 | + * @param $notify_id 通知校验ID | ||
140 | + * @return 服务器ATN结果 | ||
141 | + * 验证结果集: | ||
142 | + * invalid命令参数不对 出现这个错误,请检测返回处理中partner和key是否为空 | ||
143 | + * true 返回正确信息 | ||
144 | + * false 请检查防火墙或者是服务器阻止端口问题以及验证时间是否超过一分钟 | ||
145 | + */ | ||
146 | + function getResponse($notify_id) { | ||
147 | + $transport = $this->alipay_config['transport']; | ||
148 | + $partner = $this->alipay_config['partner']; | ||
149 | + $veryfy_url = ''; | ||
150 | + if($transport == 'https') { | ||
151 | + $veryfy_url = $this->https_verify_url; | ||
152 | + } | ||
153 | + else { | ||
154 | + $veryfy_url = $this->http_verify_url; | ||
155 | + } | ||
156 | + $veryfy_url = $veryfy_url."partner=" . $partner . "¬ify_id=" . $notify_id; | ||
157 | + $responseTxt = getHttpResponseGET($veryfy_url, $this->alipay_config['cacert']); | ||
158 | + | ||
159 | + return $responseTxt; | ||
160 | + } | ||
161 | + | ||
162 | +} | ||
163 | +?> |
1 | +<?php | ||
2 | +/** | ||
3 | + * 支付宝各接口请求提交类 | ||
4 | + * | ||
5 | + * @name AlipaySubmit | ||
6 | + * @package lib/partner/alipay | ||
7 | + * @copyright yoho.inc | ||
8 | + * @version 5.0 (2014-03-06 16:23:47) | ||
9 | + * @author fei.hong <fei.hong@yoho.cn> | ||
10 | + */ | ||
11 | +class AlipaySubmit { | ||
12 | + | ||
13 | + /** | ||
14 | + * 支付宝配置 | ||
15 | + */ | ||
16 | + var $alipay_config = array(); | ||
17 | + /** | ||
18 | + * 支付宝网关地址(新) | ||
19 | + */ | ||
20 | + var $alipay_gateway_new = 'https://mapi.alipay.com/gateway.do?'; | ||
21 | + | ||
22 | + function __construct($alipay_config){ | ||
23 | + $this->alipay_config = $alipay_config; | ||
24 | + } | ||
25 | + | ||
26 | + function AlipaySubmit($alipay_config) { | ||
27 | + $this->__construct($alipay_config); | ||
28 | + } | ||
29 | + | ||
30 | + /** | ||
31 | + * 生成签名结果 | ||
32 | + * @param $para_sort 已排序要签名的数组 | ||
33 | + * return 签名结果字符串 | ||
34 | + */ | ||
35 | + function buildRequestMysign($para_sort) { | ||
36 | + //把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串 | ||
37 | + $prestr = createLinkstring($para_sort); | ||
38 | + | ||
39 | + $mysign = ''; | ||
40 | + switch ($this->alipay_config['sign_type']) { | ||
41 | + case 'MD5' : | ||
42 | + $mysign = md5Sign($prestr, $this->alipay_config['key']); | ||
43 | + break; | ||
44 | + default : | ||
45 | + $mysign = ''; | ||
46 | + } | ||
47 | + | ||
48 | + return $mysign; | ||
49 | + } | ||
50 | + | ||
51 | + /** | ||
52 | + * 生成要请求给支付宝的参数数组 | ||
53 | + * @param $para_temp 请求前的参数数组 | ||
54 | + * @return 要请求的参数数组 | ||
55 | + */ | ||
56 | + function buildRequestPara($para_temp) { | ||
57 | + //除去待签名参数数组中的空值和签名参数 | ||
58 | + $para_filter = paraFilter($para_temp); | ||
59 | + | ||
60 | + //对待签名参数数组排序 | ||
61 | + $para_sort = argSort($para_filter); | ||
62 | + | ||
63 | + //生成签名结果 | ||
64 | + $mysign = $this->buildRequestMysign($para_sort); | ||
65 | + | ||
66 | + //签名结果与签名方式加入请求提交参数组中 | ||
67 | + $para_sort['sign'] = $mysign; | ||
68 | + $para_sort['sign_type'] = $this->alipay_config['sign_type']; | ||
69 | + | ||
70 | + return $para_sort; | ||
71 | + } | ||
72 | + | ||
73 | + /** | ||
74 | + * 生成要请求给支付宝的参数数组 | ||
75 | + * @param $para_temp 请求前的参数数组 | ||
76 | + * @return 要请求的参数数组字符串 | ||
77 | + */ | ||
78 | + function buildRequestParaToString($para_temp) { | ||
79 | + //待请求参数数组 | ||
80 | + $para = $this->buildRequestPara($para_temp); | ||
81 | + | ||
82 | + //把参数组中所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对字符串做urlencode编码 | ||
83 | + $request_data = createLinkstringUrlencode($para); | ||
84 | + | ||
85 | + return $request_data; | ||
86 | + } | ||
87 | + | ||
88 | + /** | ||
89 | + * 建立请求,以表单HTML形式构造(默认) | ||
90 | + * @param $para_temp 请求参数数组 | ||
91 | + * @param $method 提交方式。两个值可选:post、get | ||
92 | + * @param $button_name 确认按钮显示文字 | ||
93 | + * @return 提交表单HTML文本 | ||
94 | + */ | ||
95 | + function buildRequestForm($para_temp, $method) { | ||
96 | + //待请求参数数组 | ||
97 | + $para = $this->buildRequestPara($para_temp); | ||
98 | + | ||
99 | + $sHtml = "<form id='alipaysubmit' name='alipaysubmit' action='".$this->alipay_gateway_new."_input_charset=".$this->alipay_config['input_charset']."' method='".$method."'>"; | ||
100 | + while (list ($key, $val) = each ($para)) { | ||
101 | + $sHtml.= "<input type='hidden' name='".$key."' value='".$val."'/>"; | ||
102 | + } | ||
103 | + | ||
104 | + $sHtml = $sHtml."<script>document.forms['alipaysubmit'].submit();</script>"; | ||
105 | + | ||
106 | + return $sHtml; | ||
107 | + } | ||
108 | + | ||
109 | + /** | ||
110 | + * 建立请求,以模拟远程HTTP的POST请求方式构造并获取支付宝的处理结果 | ||
111 | + * @param $para_temp 请求参数数组 | ||
112 | + * @return 支付宝处理结果 | ||
113 | + */ | ||
114 | + function buildRequestHttp($para_temp) { | ||
115 | + $sResult = ''; | ||
116 | + | ||
117 | + //待请求参数数组字符串 | ||
118 | + $request_data = $this->buildRequestPara($para_temp); | ||
119 | + | ||
120 | + //远程获取数据 | ||
121 | + $sResult = getHttpResponsePOST($this->alipay_gateway_new, $this->alipay_config['cacert'],$request_data,$this->alipay_config['input_charset']); | ||
122 | + | ||
123 | + return $sResult; | ||
124 | + } | ||
125 | + | ||
126 | + /** | ||
127 | + * 建立请求,以模拟远程HTTP的POST请求方式构造并获取支付宝的处理结果,带文件上传功能 | ||
128 | + * @param $para_temp 请求参数数组 | ||
129 | + * @param $file_para_name 文件类型的参数名 | ||
130 | + * @param $file_name 文件完整绝对路径 | ||
131 | + * @return 支付宝返回处理结果 | ||
132 | + */ | ||
133 | + function buildRequestHttpInFile($para_temp, $file_para_name, $file_name) { | ||
134 | + | ||
135 | + //待请求参数数组 | ||
136 | + $para = $this->buildRequestPara($para_temp); | ||
137 | + $para[$file_para_name] = "@".$file_name; | ||
138 | + | ||
139 | + //远程获取数据 | ||
140 | + $sResult = getHttpResponsePOST($this->alipay_gateway_new, $this->alipay_config['cacert'],$para,$this->alipay_config['input_charset']); | ||
141 | + | ||
142 | + return $sResult; | ||
143 | + } | ||
144 | + | ||
145 | + /** | ||
146 | + * 用于防钓鱼,调用接口query_timestamp来获取时间戳的处理函数 | ||
147 | + * 注意:该功能PHP5环境及以上支持,因此必须服务器、本地电脑中装有支持DOMDocument、SSL的PHP配置环境。建议本地调试时使用PHP开发软件 | ||
148 | + * return 时间戳字符串 | ||
149 | + */ | ||
150 | + function query_timestamp() { | ||
151 | + $url = $this->alipay_gateway_new."service=query_timestamp&partner=".$this->alipay_config['partner']."&_input_charset=".$this->alipay_config['input_charset']; | ||
152 | + $encrypt_key = ""; | ||
153 | + | ||
154 | + $doc = new DOMDocument(); | ||
155 | + $doc->load($url); | ||
156 | + $itemEncrypt_key = $doc->getElementsByTagName( "encrypt_key" ); | ||
157 | + $encrypt_key = $itemEncrypt_key->item(0)->nodeValue; | ||
158 | + | ||
159 | + return $encrypt_key; | ||
160 | + } | ||
161 | + | ||
162 | + /** | ||
163 | + * 通过token获取用户信息 | ||
164 | + * | ||
165 | + * @param array $parameter 参数项 | ||
166 | + * @return array | ||
167 | + * @since 1.0.3 | ||
168 | + */ | ||
169 | + function getUserInfoByToken($parameter) { | ||
170 | + $parameter = $this->buildRequestPara($parameter); | ||
171 | + | ||
172 | + // 系统参数放入GET请求串 | ||
173 | + $requestUrl = $this->alipay_gateway_new . http_build_query($parameter, null, '&'); | ||
174 | + | ||
175 | + // 发起HTTP请求 | ||
176 | + $result = array(); | ||
177 | + try { | ||
178 | + $response = getHttpResponseGET($requestUrl, $this->alipay_config['cacert']); | ||
179 | + if (is_string($response)) { | ||
180 | + $result = json_decode(json_encode(simplexml_load_string($response)), true); | ||
181 | + } | ||
182 | + } catch (Exception $e) { | ||
183 | + // do nothing | ||
184 | + } | ||
185 | + return $result; | ||
186 | + } | ||
187 | + | ||
188 | +} | ||
189 | +?> |
1 | +<?php | ||
2 | +/* * | ||
3 | + * 支付宝接口公用函数 | ||
4 | + * 详细:该类是请求、通知返回两个文件所调用的公用函数核心处理文件 | ||
5 | + * 版本:3.3 | ||
6 | + * 日期:2012-07-19 | ||
7 | + * 说明: | ||
8 | + * 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。 | ||
9 | + * 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。 | ||
10 | + */ | ||
11 | + | ||
12 | +/** | ||
13 | + * 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串 | ||
14 | + * @param $para 需要拼接的数组 | ||
15 | + * return 拼接完成以后的字符串 | ||
16 | + */ | ||
17 | +function createLinkstring($para) { | ||
18 | + $arg = ""; | ||
19 | + while (list ($key, $val) = each ($para)) { | ||
20 | + $arg.=$key."=".$val."&"; | ||
21 | + } | ||
22 | + //去掉最后一个&字符 | ||
23 | + $arg = substr($arg,0,count($arg)-2); | ||
24 | + | ||
25 | + //如果存在转义字符,那么去掉转义 | ||
26 | + if(get_magic_quotes_gpc()){$arg = stripslashes($arg);} | ||
27 | + | ||
28 | + return $arg; | ||
29 | +} | ||
30 | +/** | ||
31 | + * 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对字符串做urlencode编码 | ||
32 | + * @param $para 需要拼接的数组 | ||
33 | + * return 拼接完成以后的字符串 | ||
34 | + */ | ||
35 | +function createLinkstringUrlencode($para) { | ||
36 | + $arg = ""; | ||
37 | + while (list ($key, $val) = each ($para)) { | ||
38 | + $arg.=$key."=".urlencode($val)."&"; | ||
39 | + } | ||
40 | + //去掉最后一个&字符 | ||
41 | + $arg = substr($arg,0,count($arg)-2); | ||
42 | + | ||
43 | + //如果存在转义字符,那么去掉转义 | ||
44 | + if(get_magic_quotes_gpc()){$arg = stripslashes($arg);} | ||
45 | + | ||
46 | + return $arg; | ||
47 | +} | ||
48 | +/** | ||
49 | + * 除去数组中的空值和签名参数 | ||
50 | + * @param $para 签名参数组 | ||
51 | + * return 去掉空值与签名参数后的新签名参数组 | ||
52 | + */ | ||
53 | +function paraFilter($para) { | ||
54 | + $para_filter = array(); | ||
55 | + while (list ($key, $val) = each ($para)) { | ||
56 | + if($key == "sign" || $key == "sign_type" || $val == "")continue; | ||
57 | + else $para_filter[$key] = $para[$key]; | ||
58 | + } | ||
59 | + return $para_filter; | ||
60 | +} | ||
61 | +/** | ||
62 | + * 对数组排序 | ||
63 | + * @param $para 排序前的数组 | ||
64 | + * return 排序后的数组 | ||
65 | + */ | ||
66 | +function argSort($para) { | ||
67 | + ksort($para); | ||
68 | + reset($para); | ||
69 | + return $para; | ||
70 | +} | ||
71 | +/** | ||
72 | + * 写日志,方便测试(看网站需求,也可以改成把记录存入数据库) | ||
73 | + * 注意:服务器需要开通fopen配置 | ||
74 | + * @param $word 要写入日志里的文本内容 默认值:空值 | ||
75 | + */ | ||
76 | +function logResult($word='') { | ||
77 | + $fp = fopen("log.txt","a"); | ||
78 | + flock($fp, LOCK_EX) ; | ||
79 | + fwrite($fp,"执行日期:".strftime("%Y%m%d%H%M%S",time())."\n".$word."\n"); | ||
80 | + flock($fp, LOCK_UN); | ||
81 | + fclose($fp); | ||
82 | +} | ||
83 | + | ||
84 | +/** | ||
85 | + * 远程获取数据,POST模式 | ||
86 | + * 注意: | ||
87 | + * 1.使用Crul需要修改服务器中php.ini文件的设置,找到php_curl.dll去掉前面的";"就行了 | ||
88 | + * 2.文件夹中cacert.pem是SSL证书请保证其路径有效,目前默认路径是:getcwd().'\\cacert.pem' | ||
89 | + * @param $url 指定URL完整路径地址 | ||
90 | + * @param $cacert_url 指定当前工作目录绝对路径 | ||
91 | + * @param $para 请求的数据 | ||
92 | + * @param $input_charset 编码格式。默认值:空值 | ||
93 | + * return 远程输出的数据 | ||
94 | + */ | ||
95 | +function getHttpResponsePOST($url, $cacert_url, $para, $input_charset = '') { | ||
96 | + | ||
97 | + if (trim($input_charset) != '') { | ||
98 | + $url = $url."_input_charset=".$input_charset; | ||
99 | + } | ||
100 | + $curl = curl_init($url); | ||
101 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);//SSL证书认证 | ||
102 | + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);//严格认证 | ||
103 | + curl_setopt($curl, CURLOPT_CAINFO,$cacert_url);//证书地址 | ||
104 | + curl_setopt($curl, CURLOPT_HEADER, 0 ); // 过滤HTTP头 | ||
105 | + curl_setopt($curl,CURLOPT_RETURNTRANSFER, 1);// 显示输出结果 | ||
106 | + curl_setopt($curl,CURLOPT_POST,true); // post传输数据 | ||
107 | + curl_setopt($curl,CURLOPT_POSTFIELDS,$para);// post传输数据 | ||
108 | + $responseText = curl_exec($curl); | ||
109 | + //var_dump( curl_error($curl) );//如果执行curl过程中出现异常,可打开此开关,以便查看异常内容 | ||
110 | + curl_close($curl); | ||
111 | + | ||
112 | + return $responseText; | ||
113 | +} | ||
114 | + | ||
115 | +/** | ||
116 | + * 远程获取数据,GET模式 | ||
117 | + * 注意: | ||
118 | + * 1.使用Crul需要修改服务器中php.ini文件的设置,找到php_curl.dll去掉前面的";"就行了 | ||
119 | + * 2.文件夹中cacert.pem是SSL证书请保证其路径有效,目前默认路径是:getcwd().'\\cacert.pem' | ||
120 | + * @param $url 指定URL完整路径地址 | ||
121 | + * @param $cacert_url 指定当前工作目录绝对路径 | ||
122 | + * return 远程输出的数据 | ||
123 | + */ | ||
124 | +function getHttpResponseGET($url,$cacert_url) { | ||
125 | + $curl = curl_init($url); | ||
126 | + curl_setopt($curl, CURLOPT_HEADER, 0 ); // 过滤HTTP头 | ||
127 | + curl_setopt($curl,CURLOPT_RETURNTRANSFER, 1);// 显示输出结果 | ||
128 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);//SSL证书认证 | ||
129 | + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);//严格认证 | ||
130 | + curl_setopt($curl, CURLOPT_CAINFO,$cacert_url);//证书地址 | ||
131 | + $responseText = curl_exec($curl); | ||
132 | + //var_dump( curl_error($curl) );//如果执行curl过程中出现异常,可打开此开关,以便查看异常内容 | ||
133 | + curl_close($curl); | ||
134 | + | ||
135 | + return $responseText; | ||
136 | +} | ||
137 | + | ||
138 | +/** | ||
139 | + * 实现多种字符编码方式 | ||
140 | + * @param $input 需要编码的字符串 | ||
141 | + * @param $_output_charset 输出的编码格式 | ||
142 | + * @param $_input_charset 输入的编码格式 | ||
143 | + * return 编码后的字符串 | ||
144 | + */ | ||
145 | +function charsetEncode($input,$_output_charset ,$_input_charset) { | ||
146 | + $output = ""; | ||
147 | + if(!isset($_output_charset) )$_output_charset = $_input_charset; | ||
148 | + if($_input_charset == $_output_charset || $input ==null ) { | ||
149 | + $output = $input; | ||
150 | + } elseif (function_exists("mb_convert_encoding")) { | ||
151 | + $output = mb_convert_encoding($input,$_output_charset,$_input_charset); | ||
152 | + } elseif(function_exists("iconv")) { | ||
153 | + $output = iconv($_input_charset,$_output_charset,$input); | ||
154 | + } else die("sorry, you have no libs support for charset change."); | ||
155 | + return $output; | ||
156 | +} | ||
157 | +/** | ||
158 | + * 实现多种字符解码方式 | ||
159 | + * @param $input 需要解码的字符串 | ||
160 | + * @param $_output_charset 输出的解码格式 | ||
161 | + * @param $_input_charset 输入的解码格式 | ||
162 | + * return 解码后的字符串 | ||
163 | + */ | ||
164 | +function charsetDecode($input,$_input_charset ,$_output_charset) { | ||
165 | + $output = ""; | ||
166 | + if(!isset($_input_charset) )$_input_charset = $_input_charset ; | ||
167 | + if($_input_charset == $_output_charset || $input ==null ) { | ||
168 | + $output = $input; | ||
169 | + } elseif (function_exists("mb_convert_encoding")) { | ||
170 | + $output = mb_convert_encoding($input,$_output_charset,$_input_charset); | ||
171 | + } elseif(function_exists("iconv")) { | ||
172 | + $output = iconv($_input_charset,$_output_charset,$input); | ||
173 | + } else die("sorry, you have no libs support for charset changes."); | ||
174 | + return $output; | ||
175 | +} | ||
176 | + | ||
177 | +/** MD5加密 **/ | ||
178 | + | ||
179 | +/** | ||
180 | + * 签名字符串 | ||
181 | + * @param $prestr 需要签名的字符串 | ||
182 | + * @param $key 私钥 | ||
183 | + * return 签名结果 | ||
184 | + */ | ||
185 | +function md5Sign($prestr, $key) { | ||
186 | + $prestr = $prestr . $key; | ||
187 | + return md5($prestr); | ||
188 | +} | ||
189 | + | ||
190 | +/** | ||
191 | + * 验证签名 | ||
192 | + * @param $prestr 需要签名的字符串 | ||
193 | + * @param $sign 签名结果 | ||
194 | + * @param $key 私钥 | ||
195 | + * return 签名结果 | ||
196 | + */ | ||
197 | +function md5Verify($prestr, $sign, $key) { | ||
198 | + $prestr = $prestr . $key; | ||
199 | + $mysgin = md5($prestr); | ||
200 | + | ||
201 | + if($mysgin == $sign) { | ||
202 | + return true; | ||
203 | + } | ||
204 | + else { | ||
205 | + return false; | ||
206 | + } | ||
207 | +} | ||
208 | +?> |
1 | + | ||
2 | + ╭───────────────────────╮ | ||
3 | + ────┤ 支付宝代码示例结构说明 ├──── | ||
4 | + ╰───────────────────────╯ | ||
5 | + | ||
6 | + 接口名称:支付宝快捷登录接口(alipay.auth.authorize) | ||
7 | + 代码版本:3.3 | ||
8 | + 开发语言:PHP | ||
9 | + 版 权:支付宝(中国)网络技术有限公司 | ||
10 | + 制 作 者:支付宝商户事业部技术支持组 | ||
11 | + 联系方式:商户服务电话0571-88158090 | ||
12 | + | ||
13 | + ───────────────────────────────── | ||
14 | + | ||
15 | +─────── | ||
16 | + 代码文件结构 | ||
17 | +─────── | ||
18 | + | ||
19 | +alipay.auth.authorize-php-UTF-8 | ||
20 | + │ | ||
21 | + ├lib┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈类文件夹 | ||
22 | + │ │ | ||
23 | + │ ├alipay_core.function.php ┈┈┈┈┈┈支付宝接口公用函数文件 | ||
24 | + │ │ | ||
25 | + │ ├alipay_notify.class.php┈┈┈┈┈┈┈支付宝通知处理类文件 | ||
26 | + │ │ | ||
27 | + │ ├alipay_submit.class.php┈┈┈┈┈┈┈支付宝各接口请求提交类文件 | ||
28 | + │ │ | ||
29 | + │ └alipay_md5.function.php┈┈┈┈┈┈┈支付宝接口MD5函数文件 | ||
30 | + │ | ||
31 | + ├log.txt┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈日志文件 | ||
32 | + │ | ||
33 | + ├alipay.config.php┈┈┈┈┈┈┈┈┈┈┈┈基础配置类文件 | ||
34 | + │ | ||
35 | + ├alipayapi.php┈┈┈┈┈┈┈┈┈┈┈┈┈┈支付宝接口入口文件 | ||
36 | + │ | ||
37 | + ├return_url.php ┈┈┈┈┈┈┈┈┈┈┈┈┈页面跳转同步通知文件 | ||
38 | + │ | ||
39 | + ├cacert.pem ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈用于CURL中校验SSL的CA证书文件 | ||
40 | + │ | ||
41 | + └readme.txt ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈使用说明文本 | ||
42 | + | ||
43 | +※注意※ | ||
44 | + | ||
45 | +1、必须开启curl服务 | ||
46 | +(1)使用Crul需要修改服务器中php.ini文件的设置,找到php_curl.dll去掉前面的";"即可 | ||
47 | +(2)文件夹中cacert.pem文件请务必放置到商户网站平台中(如:服务器上),并且保证其路径有效,提供的代码demo中的默认路径是当前文件夹下——getcwd().'\\cacert.pem' | ||
48 | + | ||
49 | +2、需要配置的文件是: | ||
50 | +alipay.config.php | ||
51 | +alipayapi.php | ||
52 | + | ||
53 | +●本代码示例(DEMO)采用fsockopen()的方法远程HTTP获取数据、采用DOMDocument()的方法解析XML数据。 | ||
54 | + | ||
55 | +请根据商户网站自身情况来决定是否使用代码示例中的方式—— | ||
56 | +如果不使用fsockopen,那么建议用curl来代替; | ||
57 | +如果环境不是PHP5版本或其以上,那么请用其他方法代替DOMDocument()。 | ||
58 | + | ||
59 | +curl、XML解析方法需您自行编写代码。 | ||
60 | + | ||
61 | + | ||
62 | +───────── | ||
63 | + 类文件函数结构 | ||
64 | +───────── | ||
65 | + | ||
66 | +alipay_core.function.php | ||
67 | + | ||
68 | +function createLinkstring($para) | ||
69 | +功能:把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串 | ||
70 | +输入:Array $para 需要拼接的数组 | ||
71 | +输出:String 拼接完成以后的字符串 | ||
72 | + | ||
73 | +function createLinkstringUrlencode($para) | ||
74 | +功能:把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对参数值urlencode | ||
75 | +输入:Array $para 需要拼接的数组 | ||
76 | +输出:String 拼接完成以后的字符串 | ||
77 | + | ||
78 | +function paraFilter($para) | ||
79 | +功能:除去数组中的空值和签名参数 | ||
80 | +输入:Array $para 签名参数组 | ||
81 | +输出:Array 去掉空值与签名参数后的新签名参数组 | ||
82 | + | ||
83 | +function argSort($para) | ||
84 | +功能:对数组排序 | ||
85 | +输入:Array $para 排序前的数组 | ||
86 | +输出:Array 排序后的数组 | ||
87 | + | ||
88 | +function logResult($word='') | ||
89 | +功能:写日志,方便测试(看网站需求,也可以改成存入数据库) | ||
90 | +输入:String $word 要写入日志里的文本内容 默认值:空值 | ||
91 | + | ||
92 | +function getHttpResponsePOST($url, $cacert_url, $para, $input_charset = '') | ||
93 | +功能:远程获取数据,POST模式 | ||
94 | +输入:String $url 指定URL完整路径地址 | ||
95 | + String $cacert_url 指定当前工作目录绝对路径 | ||
96 | + Array $para 请求的数据 | ||
97 | + String $input_charset 编码格式。默认值:空值 | ||
98 | +输出:String 远程输出的数据 | ||
99 | + | ||
100 | +function getHttpResponseGET($url, $cacert_url) | ||
101 | +功能:远程获取数据,GET模式 | ||
102 | +输入:String $url 指定URL完整路径地址 | ||
103 | + String $cacert_url 指定当前工作目录绝对路径 | ||
104 | +输出:String 远程输出的数据 | ||
105 | + | ||
106 | +function charsetEncode($input,$_output_charset ,$_input_charset) | ||
107 | +功能:实现多种字符编码方式 | ||
108 | +输入:String $input 需要编码的字符串 | ||
109 | + String $_output_charset 输出的编码格式 | ||
110 | + String $_input_charset 输入的编码格式 | ||
111 | +输出:String 编码后的字符串 | ||
112 | + | ||
113 | +function charsetDecode($input,$_input_charset ,$_output_charset) | ||
114 | +功能:实现多种字符解码方式 | ||
115 | +输入:String $input 需要解码的字符串 | ||
116 | + String $_output_charset 输出的解码格式 | ||
117 | + String $_input_charset 输入的解码格式 | ||
118 | +输出:String 解码后的字符串 | ||
119 | + | ||
120 | +┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉ | ||
121 | + | ||
122 | +function md5Sign($prestr, $key) | ||
123 | +功能:MD5签名 | ||
124 | +输入:String $prestr 待签名数据 | ||
125 | + String $key 私钥 | ||
126 | +输出:String 签名结果 | ||
127 | + | ||
128 | +function md5Verify($prestr, $sign, $key) | ||
129 | +功能:MD5验签 | ||
130 | +输入:String $data 待签名数据 | ||
131 | + String $sign 签名结果 | ||
132 | + String $key 私钥 | ||
133 | +输出:bool 验证结果 | ||
134 | +┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉ | ||
135 | + | ||
136 | +alipay_notify.class.php | ||
137 | + | ||
138 | +function verifyNotify() | ||
139 | +功能:对notify_url的认证 | ||
140 | +输出:Bool 验证结果:true/false | ||
141 | + | ||
142 | +function verifyReturn() | ||
143 | +功能:对return_url的认证 | ||
144 | +输出:Bool 验证结果:true/false | ||
145 | + | ||
146 | +function getSignVeryfy($para_temp, $sign) | ||
147 | +功能:获取返回时的签名验证结果 | ||
148 | +输入:Array $para_temp 通知返回来的参数数组 | ||
149 | + String $sign 支付宝返回的签名结果 | ||
150 | +输出:Bool 获得签名验证结果 | ||
151 | + | ||
152 | +function getResponse($notify_id) | ||
153 | +功能:获取远程服务器ATN结果,验证返回URL | ||
154 | +输入:String $notify_id 通知校验ID | ||
155 | +输出:String 服务器ATN结果 | ||
156 | + | ||
157 | +┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉ | ||
158 | + | ||
159 | +alipay_submit.class.php | ||
160 | + | ||
161 | +function buildRequestMysign($para_sort) | ||
162 | +功能:生成要请求给支付宝的参数数组 | ||
163 | +输入:Array $para_sort 已排序要签名的数组 | ||
164 | +输出:String 签名结果 | ||
165 | + | ||
166 | +function buildRequestPara($para_temp) | ||
167 | +功能:根据反馈回来的信息,生成签名结果 | ||
168 | +输入:Array $para_temp 请求前的参数数组 | ||
169 | +输出:String 要请求的参数数组 | ||
170 | + | ||
171 | +function buildRequestParaToString($para_temp) | ||
172 | +功能:根据反馈回来的信息,生成签名结果 | ||
173 | +输入:Array $para_temp 请求前的参数数组 | ||
174 | +输出:String 要请求的参数数组字符串 | ||
175 | + | ||
176 | +function buildRequestForm($para_temp, $method, $button_name) | ||
177 | +功能:建立请求,以表单HTML形式构造(默认) | ||
178 | +输入:Array $para_temp 请求前的参数数组 | ||
179 | + String $method 提交方式。两个值可选:post、get | ||
180 | + String $button_name 确认按钮显示文字 | ||
181 | +输出:String 提交表单HTML文本 | ||
182 | + | ||
183 | +function buildRequestHttp($para_temp) | ||
184 | +功能:建立请求,以模拟远程HTTP的POST请求方式构造并获取支付宝的处理结果 | ||
185 | +输入:Array $para_temp 请求前的参数数组 | ||
186 | +输出:String 支付宝处理结果 | ||
187 | + | ||
188 | +function buildRequestHttpInFile($para_temp, $file_para_name, $file_name) | ||
189 | +功能:建立请求,以模拟远程HTTP的POST请求方式构造并获取支付宝的处理结果,带文件上传功能 | ||
190 | +输入:Array $para_temp 请求参数数组 | ||
191 | + String $file_para_name 文件类型的参数名 | ||
192 | + String $file_name 文件完整绝对路径 | ||
193 | +输出:String 支付宝返回处理结果 | ||
194 | + | ||
195 | +function query_timestamp() | ||
196 | +功能:用于防钓鱼,调用接口query_timestamp来获取时间戳的处理函数 | ||
197 | +输出:String 时间戳字符串 | ||
198 | + | ||
199 | +┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉ | ||
200 | + | ||
201 | + | ||
202 | +────────── | ||
203 | + 出现问题,求助方法 | ||
204 | +────────── | ||
205 | + | ||
206 | +如果在集成支付宝接口时,有疑问或出现问题,可使用下面的链接,提交申请。 | ||
207 | +https://b.alipay.com/support/helperApply.htm?action=supportHome | ||
208 | +我们会有专门的技术支持人员为您处理 | ||
209 | + | ||
210 | + | ||
211 | + | ||
212 | + |
library/Plugin/Partner/qqconnect/Call.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace Plugin\Partner\Qqconnect; | ||
4 | + | ||
5 | +use Plugin\Partner\Factory; | ||
6 | + | ||
7 | +define('QC_CLASS_PATH', dirname (__FILE__) . '/class/'); | ||
8 | +require QC_CLASS_PATH . 'QC.class.php'; | ||
9 | + | ||
10 | +/** | ||
11 | + * 腾讯QQ互联的调用接口 | ||
12 | + * | ||
13 | + * @name Call | ||
14 | + * @package lib/partner/qqconnect | ||
15 | + * @copyright yoho.inc | ||
16 | + * @version 4.0 (2013-12-19 11:42:11) | ||
17 | + * @author fei.hong <fei.hong@yoho.cn> | ||
18 | + */ | ||
19 | +class Call extends Factory | ||
20 | +{ | ||
21 | + /*QQ互联对象*/ | ||
22 | + protected $qc; | ||
23 | + | ||
24 | + /** | ||
25 | + * 初始化 | ||
26 | + */ | ||
27 | + protected function init() | ||
28 | + { | ||
29 | + $this->qc = new \QC(); | ||
30 | + } | ||
31 | + | ||
32 | + /** | ||
33 | + * 获取授权URL | ||
34 | + * | ||
35 | + * @return string | ||
36 | + */ | ||
37 | + public function getAuthorizeUrl() | ||
38 | + { | ||
39 | + return $this->qc->qq_login(); | ||
40 | + } | ||
41 | + | ||
42 | + /** | ||
43 | + * 获取授权的TOKEN | ||
44 | + * | ||
45 | + * @return array | ||
46 | + */ | ||
47 | + public function getAccessToken() | ||
48 | + { | ||
49 | + $token = array(); | ||
50 | + | ||
51 | + try | ||
52 | + { | ||
53 | + $token = $this->qc->qq_callback(); | ||
54 | + $token['openid'] = $this->qc->get_openid(); | ||
55 | + } | ||
56 | + catch (Exception $e) | ||
57 | + { | ||
58 | + // do nothing | ||
59 | + } | ||
60 | + | ||
61 | + return $token; | ||
62 | + } | ||
63 | + | ||
64 | + /** | ||
65 | + * 获取当前用户的基本资料 | ||
66 | + * | ||
67 | + * @param array $token 授权成功的TOKEN, 默认为NULL | ||
68 | + * @return array | ||
69 | + */ | ||
70 | + public function getUserInfo($token) | ||
71 | + { | ||
72 | + $userInfo = array(); | ||
73 | + | ||
74 | + if (is_array($token) && isset($token['openid'])) | ||
75 | + { | ||
76 | + $this->qc = new QC($token['access_token'], $token['openid']); | ||
77 | + | ||
78 | + $userInfo = $this->qc->get_user_info(); | ||
79 | + | ||
80 | + if (isset($userInfo['ret']) && $userInfo['ret'] != 0) | ||
81 | + { | ||
82 | + $userInfo = array(); | ||
83 | + } | ||
84 | + } | ||
85 | + | ||
86 | + return $userInfo; | ||
87 | + } | ||
88 | + | ||
89 | + /** | ||
90 | + * 获取当前用户的偶像(关注)列表 | ||
91 | + * | ||
92 | + * @see http://wiki.connect.qq.com/get_idollist | ||
93 | + * @param string $access_token 访问令牌 | ||
94 | + * @param string $openid 腾讯唯一的对应QQ号 | ||
95 | + * @param array $params 参数列表 | ||
96 | + * format 是 返回数据的格式(json或xml) | ||
97 | + * reqnum 是 请求个数(1-30) | ||
98 | + * startindex 是 起始位置(第一页:填0,继续向下翻页:填上次请求返回的nextstartpos) | ||
99 | + * mode 是 获取模式,默认为0 | ||
100 | + * mode=0,新粉丝在前,只能拉取1000个 | ||
101 | + * mode=1,最多可拉取一万粉丝,暂不支持排序 | ||
102 | + * install 否 过滤安装应用好友(可选) | ||
103 | + * 0-不考虑该参数,1-获取已安装应用好友,2-获取未安装应用好友 | ||
104 | + * sex 否 按性别过滤标识,1-男,2-女,0-不进行性别过滤,默认为0,支持排序 | ||
105 | + * @return array | ||
106 | + */ | ||
107 | + public function getFriends($token, $params) | ||
108 | + { | ||
109 | + $friends = array(); | ||
110 | + | ||
111 | + if (is_array($token) && isset($token['openid'])) | ||
112 | + { | ||
113 | + $this->qc = new QC($token['access_token'], $token['openid']); | ||
114 | + | ||
115 | + $friends = $this->qc->get_idollist($params); | ||
116 | + | ||
117 | + if (isset($friends['ret']) && $friends['ret'] != 0) | ||
118 | + { | ||
119 | + $friends = array(); | ||
120 | + } | ||
121 | + } | ||
122 | + | ||
123 | + return $friends; | ||
124 | + } | ||
125 | + | ||
126 | + /** | ||
127 | + * 同步分享 | ||
128 | + * | ||
129 | + * @param array $token 授权成功的TOKEN | ||
130 | + * @param string $content 要更新的微博信息。信息内容不超过140个汉字, 为空返回400错误。 | ||
131 | + * @param string $image 要发布的图片路径, 支持url。[只支持png/jpg/gif三种格式, 增加格式请修改get_image_mime方法] | ||
132 | + * @param string $link URL地址, 通过该地址链接回来 | ||
133 | + * @return boolean false:失败, true:成功 | ||
134 | + */ | ||
135 | + public function syncShare($token, $content, $image, $link) | ||
136 | + { | ||
137 | + $result = false; | ||
138 | + | ||
139 | + if (is_array($token) && isset($token['openid'])) | ||
140 | + { | ||
141 | + $this->qc = new QC($token['access_token'], $token['openid']); | ||
142 | + | ||
143 | + $param = array('title' => '来自YOHO.CN的分享', 'url' => $link, 'summary' => $content, | ||
144 | + 'images' => $image, 'site' => 'yoho.cn', 'fromurl' => SITE_MAIN,); | ||
145 | + | ||
146 | + $response = $this->qc->add_share($param); | ||
147 | + | ||
148 | + if (isset($response['ret']) && $response['ret'] == 0) | ||
149 | + { | ||
150 | + $result = true; | ||
151 | + } | ||
152 | + } | ||
153 | + | ||
154 | + return $result; | ||
155 | + } | ||
156 | +} |
1 | +<?php | ||
2 | +defined('SITE_MAIN') || define('SITE_MAIN', 'http://www.yoho.cn'); | ||
3 | + | ||
4 | +return array( | ||
5 | + 'appid' => '100229394', | ||
6 | + 'appkey' => 'c0af9c29e0900813028c2ccb42021792', | ||
7 | + 'callback' => SITE_MAIN . '/passport/sso/partnercallback/partner/qqconnect', | ||
8 | + 'scope' => 'get_user_info,add_share,upload_pic,get_idollist,get_fanslist', | ||
9 | + 'errorReport' => false, | ||
10 | +); |
1 | +<?php | ||
2 | +/* PHP SDK | ||
3 | + * @version 2.0.0 | ||
4 | + * @author connect@qq.com | ||
5 | + * @copyright © 2013, Tencent Corporation. All rights reserved. | ||
6 | + */ | ||
7 | + | ||
8 | +require_once(QC_CLASS_PATH.'Recorder.class.php'); | ||
9 | + | ||
10 | +/* | ||
11 | + * @brief ErrorCase类,封闭异常 | ||
12 | + * */ | ||
13 | +class ErrorCase{ | ||
14 | + private $errorMsg; | ||
15 | + | ||
16 | + public function __construct(){ | ||
17 | + $this->errorMsg = array( | ||
18 | + "20001" => "<h2>配置文件损坏或无法读取,请重新执行intall</h2>", | ||
19 | + "30001" => "<h2>The state does not match. You may be a victim of CSRF.</h2>", | ||
20 | + "50001" => "<h2>可能是服务器无法请求https协议</h2>可能未开启curl支持,请尝试开启curl支持,重启web服务器,如果问题仍未解决,请联系我们" | ||
21 | + ); | ||
22 | + } | ||
23 | + | ||
24 | + /** | ||
25 | + * showError | ||
26 | + * 显示错误信息 | ||
27 | + * @param int $code 错误代码 | ||
28 | + * @param string $description 描述信息(可选) | ||
29 | + */ | ||
30 | + public function showError($code, $description = '$'){ | ||
31 | + $recorder = new Recorder(); | ||
32 | + if(! $recorder->readInc("errorReport")){ | ||
33 | + die();//die quietly | ||
34 | + } | ||
35 | + | ||
36 | + | ||
37 | + echo "<meta charset=\"UTF-8\">"; | ||
38 | + if($description == "$"){ | ||
39 | + die($this->errorMsg[$code]); | ||
40 | + }else{ | ||
41 | + echo "<h3>error:</h3>$code"; | ||
42 | + echo "<h3>msg :</h3>$description"; | ||
43 | + exit(); | ||
44 | + } | ||
45 | + } | ||
46 | + public function showTips($code, $description = '$'){ | ||
47 | + } | ||
48 | +} |
1 | +<?php | ||
2 | +/* PHP SDK | ||
3 | + * @version 2.0.0 | ||
4 | + * @author connect@qq.com | ||
5 | + * @copyright © 2013, Tencent Corporation. All rights reserved. | ||
6 | + */ | ||
7 | + | ||
8 | +require_once(QC_CLASS_PATH.'Recorder.class.php'); | ||
9 | +require_once(QC_CLASS_PATH.'URL.class.php'); | ||
10 | +require_once(QC_CLASS_PATH.'ErrorCase.class.php'); | ||
11 | + | ||
12 | +class Oauth{ | ||
13 | + | ||
14 | + const VERSION = "2.0"; | ||
15 | + const GET_AUTH_CODE_URL = "https://graph.qq.com/oauth2.0/authorize"; | ||
16 | + const GET_ACCESS_TOKEN_URL = "https://graph.qq.com/oauth2.0/token"; | ||
17 | + const GET_OPENID_URL = "https://graph.qq.com/oauth2.0/me"; | ||
18 | + | ||
19 | + protected $recorder; | ||
20 | + public $urlUtils; | ||
21 | + protected $error; | ||
22 | + | ||
23 | + | ||
24 | + function __construct(){ | ||
25 | + $this->recorder = new Recorder(); | ||
26 | + $this->urlUtils = new URL(); | ||
27 | + $this->error = new ErrorCase(); | ||
28 | + } | ||
29 | + | ||
30 | + public function qq_login(){ | ||
31 | + $appid = $this->recorder->readInc("appid"); | ||
32 | + $callback = $this->recorder->readInc("callback"); | ||
33 | + $scope = $this->recorder->readInc("scope"); | ||
34 | + | ||
35 | + //-------生成唯一随机串防CSRF攻击 | ||
36 | + $state = md5(uniqid(rand(), TRUE)); | ||
37 | +// $this->recorder->write('state',$state); | ||
38 | + $_SESSION['qqstate'] = $state; | ||
39 | + | ||
40 | + //-------构造请求参数列表 | ||
41 | + $keysArr = array( | ||
42 | + "response_type" => "code", | ||
43 | + "client_id" => $appid, | ||
44 | + "redirect_uri" => $callback, | ||
45 | + "state" => $state, | ||
46 | + "scope" => $scope | ||
47 | + ); | ||
48 | + | ||
49 | + $login_url = $this->urlUtils->combineURL(self::GET_AUTH_CODE_URL, $keysArr); | ||
50 | + | ||
51 | + header("Location:$login_url"); | ||
52 | + } | ||
53 | + | ||
54 | + public function qq_callback(){ | ||
55 | + $state = $this->recorder->read("state"); | ||
56 | + | ||
57 | + //--------验证state防止CSRF攻击 | ||
58 | +// if($_GET['state'] != $state){ | ||
59 | + if ($_GET['state'] != $_SESSION['qqstate']) { | ||
60 | + $this->error->showError("30001"); | ||
61 | + } | ||
62 | + | ||
63 | + //-------请求参数列表 | ||
64 | + $keysArr = array( | ||
65 | + "grant_type" => "authorization_code", | ||
66 | + "client_id" => $this->recorder->readInc("appid"), | ||
67 | + "redirect_uri" => urlencode($this->recorder->readInc("callback")), | ||
68 | + "client_secret" => $this->recorder->readInc("appkey"), | ||
69 | + "code" => $_GET['code'] | ||
70 | + ); | ||
71 | + | ||
72 | + //------构造请求access_token的url | ||
73 | + $token_url = $this->urlUtils->combineURL(self::GET_ACCESS_TOKEN_URL, $keysArr); | ||
74 | + $response = $this->urlUtils->get_contents($token_url); | ||
75 | + | ||
76 | + if(strpos($response, "callback") !== false){ | ||
77 | + | ||
78 | + $lpos = strpos($response, "("); | ||
79 | + $rpos = strrpos($response, ")"); | ||
80 | + $response = substr($response, $lpos + 1, $rpos - $lpos -1); | ||
81 | + $msg = json_decode($response); | ||
82 | + | ||
83 | + if(isset($msg->error)){ | ||
84 | + $this->error->showError($msg->error, $msg->error_description); | ||
85 | + } | ||
86 | + } | ||
87 | + | ||
88 | + $params = array(); | ||
89 | + parse_str($response, $params); | ||
90 | + | ||
91 | + $this->recorder->write("access_token", $params["access_token"]); | ||
92 | +// return $params["access_token"]; | ||
93 | + | ||
94 | + // 根据业务需要改造了一下 | ||
95 | + return $params; | ||
96 | + } | ||
97 | + | ||
98 | + public function get_openid(){ | ||
99 | + | ||
100 | + //-------请求参数列表 | ||
101 | + $keysArr = array( | ||
102 | + "access_token" => $this->recorder->read("access_token") | ||
103 | + ); | ||
104 | + | ||
105 | + $graph_url = $this->urlUtils->combineURL(self::GET_OPENID_URL, $keysArr); | ||
106 | + $response = $this->urlUtils->get_contents($graph_url); | ||
107 | + | ||
108 | + //--------检测错误是否发生 | ||
109 | + if(strpos($response, "callback") !== false){ | ||
110 | + | ||
111 | + $lpos = strpos($response, "("); | ||
112 | + $rpos = strrpos($response, ")"); | ||
113 | + $response = substr($response, $lpos + 1, $rpos - $lpos -1); | ||
114 | + } | ||
115 | + | ||
116 | + $user = json_decode($response); | ||
117 | + if(isset($user->error)){ | ||
118 | + $this->error->showError($user->error, $user->error_description); | ||
119 | + } | ||
120 | + | ||
121 | + //------记录openid | ||
122 | + $this->recorder->write("openid", $user->openid); | ||
123 | + return $user->openid; | ||
124 | + | ||
125 | + } | ||
126 | +} |
1 | +<?php | ||
2 | +/* PHP SDK | ||
3 | + * @version 2.0.0 | ||
4 | + * @author connect@qq.com | ||
5 | + * @copyright © 2013, Tencent Corporation. All rights reserved. | ||
6 | + */ | ||
7 | +require_once(QC_CLASS_PATH.'Oauth.class.php'); | ||
8 | + | ||
9 | +/* | ||
10 | + * @brief QC类,api外部对象,调用接口全部依赖于此对象 | ||
11 | + * */ | ||
12 | +class QC extends Oauth{ | ||
13 | + private $kesArr, $APIMap; | ||
14 | + | ||
15 | + /** | ||
16 | + * _construct | ||
17 | + * | ||
18 | + * 构造方法 | ||
19 | + * @access public | ||
20 | + * @since 5 | ||
21 | + * @param string $access_token access_token value | ||
22 | + * @param string $openid openid value | ||
23 | + * @return Object QC | ||
24 | + */ | ||
25 | + public function __construct($access_token = "", $openid = ""){ | ||
26 | + parent::__construct(); | ||
27 | + | ||
28 | + //如果access_token和openid为空,则从session里去取,适用于demo展示情形 | ||
29 | + if($access_token === "" || $openid === ""){ | ||
30 | + $this->keysArr = array( | ||
31 | + "oauth_consumer_key" => (int)$this->recorder->readInc("appid"), | ||
32 | + "access_token" => $this->recorder->read("access_token"), | ||
33 | + "openid" => $this->recorder->read("openid") | ||
34 | + ); | ||
35 | + }else{ | ||
36 | + $this->keysArr = array( | ||
37 | + "oauth_consumer_key" => (int)$this->recorder->readInc("appid"), | ||
38 | + "access_token" => $access_token, | ||
39 | + "openid" => $openid | ||
40 | + ); | ||
41 | + } | ||
42 | + | ||
43 | + //初始化APIMap | ||
44 | + /* | ||
45 | + * 加#表示非必须,无则不传入url(url中不会出现该参数), "key" => "val" 表示key如果没有定义则使用默认值val | ||
46 | + * 规则 array( baseUrl, argListArr, method) | ||
47 | + */ | ||
48 | + $this->APIMap = array( | ||
49 | + | ||
50 | + | ||
51 | + /* qzone */ | ||
52 | + "add_blog" => array( | ||
53 | + "https://graph.qq.com/blog/add_one_blog", | ||
54 | + array("title", "format" => "json", "content" => null), | ||
55 | + "POST" | ||
56 | + ), | ||
57 | + "add_topic" => array( | ||
58 | + "https://graph.qq.com/shuoshuo/add_topic", | ||
59 | + array("richtype","richval","con","#lbs_nm","#lbs_x","#lbs_y","format" => "json", "#third_source"), | ||
60 | + "POST" | ||
61 | + ), | ||
62 | + "get_user_info" => array( | ||
63 | + "https://graph.qq.com/user/get_user_info", | ||
64 | + array("format" => "json"), | ||
65 | + "GET" | ||
66 | + ), | ||
67 | + "add_one_blog" => array( | ||
68 | + "https://graph.qq.com/blog/add_one_blog", | ||
69 | + array("title", "content", "format" => "json"), | ||
70 | + "GET" | ||
71 | + ), | ||
72 | + "add_album" => array( | ||
73 | + "https://graph.qq.com/photo/add_album", | ||
74 | + array("albumname", "#albumdesc", "#priv", "format" => "json"), | ||
75 | + "POST" | ||
76 | + ), | ||
77 | + "upload_pic" => array( | ||
78 | + "https://graph.qq.com/photo/upload_pic", | ||
79 | + array("picture", "#photodesc", "#title", "#albumid", "#mobile", "#x", "#y", "#needfeed", "#successnum", "#picnum", "format" => "json"), | ||
80 | + "POST" | ||
81 | + ), | ||
82 | + "list_album" => array( | ||
83 | + "https://graph.qq.com/photo/list_album", | ||
84 | + array("format" => "json") | ||
85 | + ), | ||
86 | + "add_share" => array( | ||
87 | + "https://graph.qq.com/share/add_share", | ||
88 | + array("title", "url", "#comment","#summary","#images","format" => "json","#type","#playurl","#nswb","site","fromurl"), | ||
89 | + "POST" | ||
90 | + ), | ||
91 | + "check_page_fans" => array( | ||
92 | + "https://graph.qq.com/user/check_page_fans", | ||
93 | + array("page_id" => "314416946","format" => "json") | ||
94 | + ), | ||
95 | + /* wblog */ | ||
96 | + | ||
97 | + "add_t" => array( | ||
98 | + "https://graph.qq.com/t/add_t", | ||
99 | + array("format" => "json", "content","#clientip","#longitude","#compatibleflag"), | ||
100 | + "POST" | ||
101 | + ), | ||
102 | + "add_pic_t" => array( | ||
103 | + "https://graph.qq.com/t/add_pic_t", | ||
104 | + array("content", "pic", "format" => "json", "#clientip", "#longitude", "#latitude", "#syncflag", "#compatiblefalg"), | ||
105 | + "POST" | ||
106 | + ), | ||
107 | + "del_t" => array( | ||
108 | + "https://graph.qq.com/t/del_t", | ||
109 | + array("id", "format" => "json"), | ||
110 | + "POST" | ||
111 | + ), | ||
112 | + "get_repost_list" => array( | ||
113 | + "https://graph.qq.com/t/get_repost_list", | ||
114 | + array("flag", "rootid", "pageflag", "pagetime", "reqnum", "twitterid", "format" => "json") | ||
115 | + ), | ||
116 | + "get_info" => array( | ||
117 | + "https://graph.qq.com/user/get_info", | ||
118 | + array("format" => "json") | ||
119 | + ), | ||
120 | + "get_other_info" => array( | ||
121 | + "https://graph.qq.com/user/get_other_info", | ||
122 | + array("format" => "json", "#name", "fopenid") | ||
123 | + ), | ||
124 | + "get_fanslist" => array( | ||
125 | + "https://graph.qq.com/relation/get_fanslist", | ||
126 | + array("format" => "json", "reqnum", "startindex", "#mode", "#install", "#sex") | ||
127 | + ), | ||
128 | + "get_idollist" => array( | ||
129 | + "https://graph.qq.com/relation/get_idollist", | ||
130 | + array("format" => "json", "reqnum", "startindex", "#mode", "#install") | ||
131 | + ), | ||
132 | + "add_idol" => array( | ||
133 | + "https://graph.qq.com/relation/add_idol", | ||
134 | + array("format" => "json", "#name-1", "#fopenids-1"), | ||
135 | + "POST" | ||
136 | + ), | ||
137 | + "del_idol" => array( | ||
138 | + "https://graph.qq.com/relation/del_idol", | ||
139 | + array("format" => "json", "#name-1", "#fopenid-1"), | ||
140 | + "POST" | ||
141 | + ), | ||
142 | + /* pay */ | ||
143 | + | ||
144 | + "get_tenpay_addr" => array( | ||
145 | + "https://graph.qq.com/cft_info/get_tenpay_addr", | ||
146 | + array("ver" => 1,"limit" => 5,"offset" => 0,"format" => "json") | ||
147 | + ) | ||
148 | + ); | ||
149 | + } | ||
150 | + | ||
151 | + //调用相应api | ||
152 | + private function _applyAPI($arr, $argsList, $baseUrl, $method){ | ||
153 | + $pre = "#"; | ||
154 | + $keysArr = $this->keysArr; | ||
155 | + | ||
156 | + $optionArgList = array();//一些多项选填参数必选一的情形 | ||
157 | + foreach($argsList as $key => $val){ | ||
158 | + $tmpKey = $key; | ||
159 | + $tmpVal = $val; | ||
160 | + | ||
161 | + if(!is_string($key)){ | ||
162 | + $tmpKey = $val; | ||
163 | + | ||
164 | + if(strpos($val,$pre) === 0){ | ||
165 | + $tmpVal = $pre; | ||
166 | + $tmpKey = substr($tmpKey,1); | ||
167 | + if(preg_match("/-(\d$)/", $tmpKey, $res)){ | ||
168 | + $tmpKey = str_replace($res[0], "", $tmpKey); | ||
169 | + $optionArgList[$res[1]][] = $tmpKey; | ||
170 | + } | ||
171 | + }else{ | ||
172 | + $tmpVal = null; | ||
173 | + } | ||
174 | + } | ||
175 | + | ||
176 | + //-----如果没有设置相应的参数 | ||
177 | + if(!isset($arr[$tmpKey]) || $arr[$tmpKey] === ""){ | ||
178 | + | ||
179 | + if($tmpVal == $pre){//则使用默认的值 | ||
180 | + continue; | ||
181 | + }else if($tmpVal){ | ||
182 | + $arr[$tmpKey] = $tmpVal; | ||
183 | + }else{ | ||
184 | + if($v = $_FILES[$tmpKey]){ | ||
185 | + | ||
186 | + $filename = dirname($v['tmp_name'])."/".$v['name']; | ||
187 | + move_uploaded_file($v['tmp_name'], $filename); | ||
188 | + $arr[$tmpKey] = "@$filename"; | ||
189 | + | ||
190 | + }else{ | ||
191 | + $this->error->showError("api调用参数错误","未传入参数$tmpKey"); | ||
192 | + } | ||
193 | + } | ||
194 | + } | ||
195 | + | ||
196 | + $keysArr[$tmpKey] = $arr[$tmpKey]; | ||
197 | + } | ||
198 | + //检查选填参数必填一的情形 | ||
199 | + foreach($optionArgList as $val){ | ||
200 | + $n = 0; | ||
201 | + foreach($val as $v){ | ||
202 | + if(in_array($v, array_keys($keysArr))){ | ||
203 | + $n ++; | ||
204 | + } | ||
205 | + } | ||
206 | + | ||
207 | + if(! $n){ | ||
208 | + $str = implode(",",$val); | ||
209 | + $this->error->showError("api调用参数错误",$str."必填一个"); | ||
210 | + } | ||
211 | + } | ||
212 | + | ||
213 | + if($method == "POST"){ | ||
214 | + if($baseUrl == "https://graph.qq.com/blog/add_one_blog") $response = $this->urlUtils->post($baseUrl, $keysArr, 1); | ||
215 | + else $response = $this->urlUtils->post($baseUrl, $keysArr, 0); | ||
216 | + }else if($method == "GET"){ | ||
217 | + $response = $this->urlUtils->get($baseUrl, $keysArr); | ||
218 | + } | ||
219 | + | ||
220 | + return $response; | ||
221 | + | ||
222 | + } | ||
223 | + | ||
224 | + /** | ||
225 | + * _call | ||
226 | + * 魔术方法,做api调用转发 | ||
227 | + * @param string $name 调用的方法名称 | ||
228 | + * @param array $arg 参数列表数组 | ||
229 | + * @since 5.0 | ||
230 | + * @return array 返加调用结果数组 | ||
231 | + */ | ||
232 | + public function __call($name,$arg){ | ||
233 | + //如果APIMap不存在相应的api | ||
234 | + if(empty($this->APIMap[$name])){ | ||
235 | + $this->error->showError("api调用名称错误","不存在的API: <span style='color:red;'>$name</span>"); | ||
236 | + } | ||
237 | + | ||
238 | + //从APIMap获取api相应参数 | ||
239 | + $baseUrl = $this->APIMap[$name][0]; | ||
240 | + $argsList = $this->APIMap[$name][1]; | ||
241 | + $method = isset($this->APIMap[$name][2]) ? $this->APIMap[$name][2] : "GET"; | ||
242 | + | ||
243 | + if(empty($arg)){ | ||
244 | + $arg[0] = null; | ||
245 | + } | ||
246 | + | ||
247 | + //对于get_tenpay_addr,特殊处理,php json_decode对\xA312此类字符支持不好 | ||
248 | + if($name != "get_tenpay_addr"){ | ||
249 | + $response = json_decode($this->_applyAPI($arg[0], $argsList, $baseUrl, $method)); | ||
250 | + $responseArr = $this->objToArr($response); | ||
251 | + }else{ | ||
252 | + $responseArr = $this->simple_json_parser($this->_applyAPI($arg[0], $argsList, $baseUrl, $method)); | ||
253 | + } | ||
254 | + | ||
255 | + // 根据业务需求,返回结果 | ||
256 | + //检查返回ret判断api是否成功调用 | ||
257 | +// if($responseArr['ret'] == 0){ | ||
258 | +// return $responseArr; | ||
259 | +// }else{ | ||
260 | +// $this->error->showError($response->ret, $response->msg); | ||
261 | +// } | ||
262 | + | ||
263 | + return $responseArr; | ||
264 | + } | ||
265 | + | ||
266 | + //php 对象到数组转换 | ||
267 | + private function objToArr($obj){ | ||
268 | + if(!is_object($obj) && !is_array($obj)) { | ||
269 | + return $obj; | ||
270 | + } | ||
271 | + $arr = array(); | ||
272 | + foreach($obj as $k => $v){ | ||
273 | + $arr[$k] = $this->objToArr($v); | ||
274 | + } | ||
275 | + return $arr; | ||
276 | + } | ||
277 | + | ||
278 | + | ||
279 | + /** | ||
280 | + * get_access_token | ||
281 | + * 获得access_token | ||
282 | + * @param void | ||
283 | + * @since 5.0 | ||
284 | + * @return string 返加access_token | ||
285 | + */ | ||
286 | + public function get_access_token(){ | ||
287 | + return $this->recorder->read("access_token"); | ||
288 | + } | ||
289 | + | ||
290 | + //简单实现json到php数组转换功能 | ||
291 | + private function simple_json_parser($json){ | ||
292 | + $json = str_replace("{","",str_replace("}","", $json)); | ||
293 | + $jsonValue = explode(",", $json); | ||
294 | + $arr = array(); | ||
295 | + foreach($jsonValue as $v){ | ||
296 | + $jValue = explode(":", $v); | ||
297 | + $arr[str_replace('"',"", $jValue[0])] = (str_replace('"', "", $jValue[1])); | ||
298 | + } | ||
299 | + return $arr; | ||
300 | + } | ||
301 | +} |
1 | +<?php | ||
2 | +/* PHP SDK | ||
3 | + * @version 2.0.0 | ||
4 | + * @author connect@qq.com | ||
5 | + * @copyright © 2013, Tencent Corporation. All rights reserved. | ||
6 | + */ | ||
7 | + | ||
8 | +require_once(QC_CLASS_PATH.'ErrorCase.class.php'); | ||
9 | + | ||
10 | +class Recorder{ | ||
11 | + private static $data; | ||
12 | + private $inc; | ||
13 | + private $error; | ||
14 | + | ||
15 | + public function __construct(){ | ||
16 | + $this->error = new ErrorCase(); | ||
17 | + | ||
18 | + //-------读取配置文件 | ||
19 | + $this->inc = require(QC_CLASS_PATH.'../Config.inc.php'); | ||
20 | + | ||
21 | + if(empty($this->inc)){ | ||
22 | + $this->error->showError("20001"); | ||
23 | + } | ||
24 | + | ||
25 | + if(empty($_SESSION['QC_userData'])){ | ||
26 | + self::$data = array(); | ||
27 | + }else{ | ||
28 | + self::$data = $_SESSION['QC_userData']; | ||
29 | + } | ||
30 | + } | ||
31 | + | ||
32 | + public function write($name,$value){ | ||
33 | + self::$data[$name] = $value; | ||
34 | + } | ||
35 | + | ||
36 | + public function read($name){ | ||
37 | + if(empty(self::$data[$name])){ | ||
38 | + return null; | ||
39 | + }else{ | ||
40 | + return self::$data[$name]; | ||
41 | + } | ||
42 | + } | ||
43 | + | ||
44 | + public function readInc($name){ | ||
45 | + if(empty($this->inc[$name])){ | ||
46 | + return null; | ||
47 | + }else{ | ||
48 | + return $this->inc[$name]; | ||
49 | + } | ||
50 | + } | ||
51 | + | ||
52 | + public function delete($name){ | ||
53 | + unset(self::$data[$name]); | ||
54 | + } | ||
55 | + | ||
56 | + function __destruct(){ | ||
57 | + $_SESSION['QC_userData'] = self::$data; | ||
58 | + } | ||
59 | +} |
1 | +<?php | ||
2 | +/* PHP SDK | ||
3 | + * @version 2.0.0 | ||
4 | + * @author connect@qq.com | ||
5 | + * @copyright © 2013, Tencent Corporation. All rights reserved. | ||
6 | + */ | ||
7 | + | ||
8 | +require_once(QC_CLASS_PATH.'ErrorCase.class.php'); | ||
9 | + | ||
10 | +/* | ||
11 | + * @brief url封装类,将常用的url请求操作封装在一起 | ||
12 | + * */ | ||
13 | +class URL{ | ||
14 | + private $error; | ||
15 | + | ||
16 | + public function __construct(){ | ||
17 | + $this->error = new ErrorCase(); | ||
18 | + } | ||
19 | + | ||
20 | + /** | ||
21 | + * combineURL | ||
22 | + * 拼接url | ||
23 | + * @param string $baseURL 基于的url | ||
24 | + * @param array $keysArr 参数列表数组 | ||
25 | + * @return string 返回拼接的url | ||
26 | + */ | ||
27 | + public function combineURL($baseURL,$keysArr){ | ||
28 | + $combined = $baseURL."?"; | ||
29 | + $valueArr = array(); | ||
30 | + | ||
31 | + foreach($keysArr as $key => $val){ | ||
32 | + $valueArr[] = "$key=$val"; | ||
33 | + } | ||
34 | + | ||
35 | + $keyStr = implode("&",$valueArr); | ||
36 | + $combined .= ($keyStr); | ||
37 | + | ||
38 | + return $combined; | ||
39 | + } | ||
40 | + | ||
41 | + /** | ||
42 | + * get_contents | ||
43 | + * 服务器通过get请求获得内容 | ||
44 | + * @param string $url 请求的url,拼接后的 | ||
45 | + * @return string 请求返回的内容 | ||
46 | + */ | ||
47 | + public function get_contents($url){ | ||
48 | + if (ini_get("allow_url_fopen") == "1") { | ||
49 | + //2015-3-5 wuxiao 尝试解决Maximum execution time of 30 seconds exceeded | ||
50 | + //$response = file_get_contents($url); | ||
51 | + $response = file_get_contents($url, false, stream_context_create(array( | ||
52 | + 'http' => array( | ||
53 | + 'method' => "GET", | ||
54 | + 'timeout' => 10, | ||
55 | + ) | ||
56 | + ))); | ||
57 | + }else{ | ||
58 | + $ch = curl_init(); | ||
59 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); | ||
60 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | ||
61 | + curl_setopt($ch, CURLOPT_URL, $url); | ||
62 | + | ||
63 | + //2015-3-5 wuxiao 尝试解决Maximum execution time of 30 seconds exceeded | ||
64 | + curl_setopt ( $ci, CURLOPT_CONNECTTIMEOUT, 3 ); | ||
65 | + curl_setopt ( $ci, CURLOPT_TIMEOUT, 7 ); | ||
66 | + | ||
67 | + $response = curl_exec($ch); | ||
68 | + curl_close($ch); | ||
69 | + } | ||
70 | + | ||
71 | + //-------请求为空 | ||
72 | + if(empty($response)){ | ||
73 | + $this->error->showError("50001"); | ||
74 | + } | ||
75 | + | ||
76 | + return $response; | ||
77 | + } | ||
78 | + | ||
79 | + /** | ||
80 | + * get | ||
81 | + * get方式请求资源 | ||
82 | + * @param string $url 基于的baseUrl | ||
83 | + * @param array $keysArr 参数列表数组 | ||
84 | + * @return string 返回的资源内容 | ||
85 | + */ | ||
86 | + public function get($url, $keysArr){ | ||
87 | + $combined = $this->combineURL($url, $keysArr); | ||
88 | + return $this->get_contents($combined); | ||
89 | + } | ||
90 | + | ||
91 | + /** | ||
92 | + * post | ||
93 | + * post方式请求资源 | ||
94 | + * @param string $url 基于的baseUrl | ||
95 | + * @param array $keysArr 请求的参数列表 | ||
96 | + * @param int $flag 标志位 | ||
97 | + * @return string 返回的资源内容 | ||
98 | + */ | ||
99 | + public function post($url, $keysArr, $flag = 0){ | ||
100 | + | ||
101 | + $ch = curl_init(); | ||
102 | + if(! $flag) curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); | ||
103 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | ||
104 | + curl_setopt($ch, CURLOPT_POST, TRUE); | ||
105 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $keysArr); | ||
106 | + curl_setopt($ch, CURLOPT_URL, $url); | ||
107 | + | ||
108 | + //2015-3-5 wuxiao 尝试解决Maximum execution time of 30 seconds exceeded | ||
109 | + curl_setopt ( $ci, CURLOPT_CONNECTTIMEOUT, 3 ); | ||
110 | + curl_setopt ( $ci, CURLOPT_TIMEOUT, 7 ); | ||
111 | + | ||
112 | + $ret = curl_exec($ch); | ||
113 | + | ||
114 | + curl_close($ch); | ||
115 | + return $ret; | ||
116 | + } | ||
117 | +} |
library/Plugin/Partner/sinaweibo/Call.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace Plugin\Partner\Sinaweibo; | ||
4 | + | ||
5 | +use Plugin\Partner\Factory; | ||
6 | + | ||
7 | +require dirname(__FILE__) . '/class/Saev2.class.php'; | ||
8 | + | ||
9 | +/** | ||
10 | + * 新浪微博的调用接口 | ||
11 | + * | ||
12 | + * @name Call | ||
13 | + * @package lib/partner/sinaweibo | ||
14 | + * @copyright yoho.inc | ||
15 | + * @version 4.0 (2013-12-19 11:45:51) | ||
16 | + * @author fei.hong <fei.hong@yoho.cn> | ||
17 | + */ | ||
18 | +class Call extends Factory | ||
19 | +{ | ||
20 | + /*OAuth2.0对象*/ | ||
21 | + protected $oauth; | ||
22 | + | ||
23 | + /*客户端操作对象*/ | ||
24 | + protected $client; | ||
25 | + | ||
26 | + /** | ||
27 | + * 初始化 | ||
28 | + */ | ||
29 | + protected function init() | ||
30 | + { | ||
31 | + $this->oauth = new \SaeTOAuthV2($this->apiConfig['appId'], $this->apiConfig['appKey']); | ||
32 | + } | ||
33 | + | ||
34 | + /** | ||
35 | + * 获取授权URL | ||
36 | + */ | ||
37 | + public function getAuthorizeUrl() | ||
38 | + { | ||
39 | + return $this->oauth->getAuthorizeURL($this->apiConfig['appCallbackUrl']); | ||
40 | + } | ||
41 | + | ||
42 | + /** | ||
43 | + * 获取授权的TOKEN | ||
44 | + */ | ||
45 | + public function getAccessToken() | ||
46 | + { | ||
47 | + $token = array(); | ||
48 | + | ||
49 | + if (isset($_REQUEST['code'])) | ||
50 | + { | ||
51 | + $keys = array(); | ||
52 | + $keys['code'] = $_REQUEST['code']; | ||
53 | + $keys['redirect_uri'] = $this->apiConfig['appCallbackUrl']; | ||
54 | + | ||
55 | + try | ||
56 | + { | ||
57 | + $token = $this->oauth->getAccessToken('code', $keys); | ||
58 | + } | ||
59 | + catch (Exception $e) | ||
60 | + { | ||
61 | + // do nothing | ||
62 | + } | ||
63 | + } | ||
64 | + | ||
65 | + return $token; | ||
66 | + } | ||
67 | + | ||
68 | + /** | ||
69 | + * 获取当前用户的基本资料 | ||
70 | + * | ||
71 | + * @param array $token 授权成功的TOKEN, 默认为NULL | ||
72 | + * @return array | ||
73 | + */ | ||
74 | + public function getUserInfo($token) | ||
75 | + { | ||
76 | + $userInfo = array(); | ||
77 | + | ||
78 | + if (is_array($token) && isset($token['uid'])) | ||
79 | + { | ||
80 | + $this->client = new SaeTClientV2($this->apiConfig['appId'], $this->apiConfig['appKey'], $token['access_token']); | ||
81 | + | ||
82 | + $userInfo = $this->client->show_user_by_id($token['uid']); | ||
83 | + | ||
84 | + if (isset($userInfo['error_code']) && $userInfo['error_code'] > 0) | ||
85 | + { | ||
86 | + $userInfo = array(); | ||
87 | + } | ||
88 | + } | ||
89 | + | ||
90 | + return $userInfo; | ||
91 | + } | ||
92 | + | ||
93 | + /** | ||
94 | + * 获取当前用户的关注列表 | ||
95 | + * | ||
96 | + * @see http://open.weibo.com/wiki/2/friendships/friends | ||
97 | + * | ||
98 | + * @param string $token 已授权过的访问TOKEN | ||
99 | + * @param array $params 参数列表,如下: | ||
100 | + * @param integer $uid (要获取的用户的ID) | ||
101 | + * @param integer count (单页返回的记录条数,默认为50,最大不超过200。) | ||
102 | + * @param integer cursor (返回结果的游标,下一页用返回值里的next_cursor,上一页用previous_cursor,默认为0。 | ||
103 | + * @return array | ||
104 | + */ | ||
105 | + public function getFriends($token, $params) | ||
106 | + { | ||
107 | + $result = array(); | ||
108 | + | ||
109 | + if (is_array($token) && isset($token['access_token'])) | ||
110 | + { | ||
111 | + $this->client = new SaeTClientV2($this->apiConfig['appId'], $this->apiConfig['appKey'], $token['access_token']); | ||
112 | + | ||
113 | + $result = $this->client->friends_by_id($params['uid'], $params['cursor'], $params['count']); | ||
114 | + | ||
115 | + if (isset($result['error_code']) && $result['error_code'] > 0) | ||
116 | + { | ||
117 | + $result = array(); | ||
118 | + } | ||
119 | + } | ||
120 | + | ||
121 | + return $result; | ||
122 | + } | ||
123 | + | ||
124 | + /** | ||
125 | + * 获取用户的双向关注列表,即互粉列表 | ||
126 | + * | ||
127 | + * @param type $token 授权成功的TOKEN | ||
128 | + * @param type $params 参数列表 | ||
129 | + */ | ||
130 | + public function getBilateral($token, $params) | ||
131 | + { | ||
132 | + $result = array(); | ||
133 | + | ||
134 | + if (is_array($token) && isset($token['access_token'])) | ||
135 | + { | ||
136 | + $this->client = new SaeTClientV2($this->apiConfig['appId'], $this->apiConfig['appKey'], $token['access_token']); | ||
137 | + | ||
138 | + $result = $this->client->bilateral($params['uid'], $params['page'], $params['count']); | ||
139 | + | ||
140 | + if (isset($result['error_code']) && $result['error_code'] > 0) | ||
141 | + { | ||
142 | + $result = array(); | ||
143 | + } | ||
144 | + } | ||
145 | + | ||
146 | + return $result; | ||
147 | + } | ||
148 | + | ||
149 | + /** | ||
150 | + * 同步分享 | ||
151 | + * | ||
152 | + * @param array $token 授权成功的TOKEN | ||
153 | + * @param string $content 要更新的微博信息。信息内容不超过140个汉字, 为空返回400错误。 | ||
154 | + * @param string $image 要发布的图片路径, 支持url。[只支持png/jpg/gif三种格式, 增加格式请修改get_image_mime方法] | ||
155 | + * @param string $link URL地址, 通过该地址链接回来 | ||
156 | + * @return boolean false:失败, true:成功 | ||
157 | + */ | ||
158 | + public function syncShare($token, $content, $image, $link) | ||
159 | + { | ||
160 | + $result = false; | ||
161 | + | ||
162 | + if (is_array($token) && isset($token['access_token'])) | ||
163 | + { | ||
164 | + $content .= $link; | ||
165 | + | ||
166 | + $this->client = new SaeTClientV2($this->apiConfig['appId'], $this->apiConfig['appKey'], $token['access_token']); | ||
167 | + | ||
168 | + $response = $this->client->upload($content, $image); | ||
169 | + | ||
170 | + if (!isset($response['error_code']) || $response['error_code'] == 0) | ||
171 | + { | ||
172 | + $result = true; | ||
173 | + } | ||
174 | + } | ||
175 | + | ||
176 | + return $result; | ||
177 | + } | ||
178 | + | ||
179 | + /** | ||
180 | + * 加关注 | ||
181 | + * | ||
182 | + * @param array $token 访问令牌 | ||
183 | + * @param integer $uid 需要关注的用户ID | ||
184 | + * @param string $screenName 需要关注的用户昵称 | ||
185 | + * @return array | ||
186 | + */ | ||
187 | + public function follow($token, $uid = null, $screenName = null) | ||
188 | + { | ||
189 | + $result = array(); | ||
190 | + | ||
191 | + if (is_array($token) && isset($token['access_token'])) | ||
192 | + { | ||
193 | + $this->client = new SaeTClientV2($this->apiConfig['appId'], $this->apiConfig['appKey'], $token['access_token']); | ||
194 | + | ||
195 | + if ($uid !== null) | ||
196 | + { | ||
197 | + $result = $this->client->follow_by_id($uid); | ||
198 | + } | ||
199 | + elseif ($screenName !== null) | ||
200 | + { | ||
201 | + $result = $this->client->follow_by_name($screenName); | ||
202 | + } | ||
203 | + } | ||
204 | + | ||
205 | + return $result; | ||
206 | + } | ||
207 | + | ||
208 | + /** | ||
209 | + * 发布文字微博 | ||
210 | + * | ||
211 | + * @param array $token 访问令牌 | ||
212 | + * @param string $content 要发布的微博文本内容,必须做URLencode,内容不超过140个汉字 | ||
213 | + * @return array | ||
214 | + */ | ||
215 | + public function publish($token, $content) | ||
216 | + { | ||
217 | + $result = array(); | ||
218 | + | ||
219 | + if (is_array($token) && isset($token['access_token']) && is_string($content)) | ||
220 | + { | ||
221 | + $this->client = new SaeTClientV2($this->apiConfig['appId'], $this->apiConfig['appKey'], $token['access_token']); | ||
222 | + | ||
223 | + $this->client->update($content); | ||
224 | + } | ||
225 | + | ||
226 | + return $result; | ||
227 | + } | ||
228 | + | ||
229 | + /** | ||
230 | + * 发送一条私信 | ||
231 | + * | ||
232 | + * @param integer $uid 用户UID | ||
233 | + * @param string $text 要发生的消息内容,文本大小必须小于300个汉字 | ||
234 | + * @param integer $id 需要发送的微博ID | ||
235 | + * @return void | ||
236 | + */ | ||
237 | + public function sendMessage($token, $uid, $content, $id = null) | ||
238 | + { | ||
239 | + if (is_array($token) && isset($token['access_token']) && isset($uid)) | ||
240 | + { | ||
241 | + $this->client = new SaeTClientV2($this->apiConfig['appId'], $this->apiConfig['appKey'], $token['access_token']); | ||
242 | + $this->client->send_dm_by_id($uid, $content, $id); | ||
243 | + } | ||
244 | + } | ||
245 | + | ||
246 | +} |
This diff could not be displayed because it is too large.
1 | <?php | 1 | <?php |
2 | use Action\AbstractAction; | 2 | use Action\AbstractAction; |
3 | -use LibModels\Wap\Home\IndexData as Index; | 3 | +use LibModels\Wap\Home\IndexData; |
4 | 4 | ||
5 | /** | 5 | /** |
6 | * 频道选择 | 6 | * 频道选择 |
@@ -9,12 +9,12 @@ class IndexController extends AbstractAction | @@ -9,12 +9,12 @@ class IndexController extends AbstractAction | ||
9 | { | 9 | { |
10 | 10 | ||
11 | /** | 11 | /** |
12 | - * 启动首页 | 12 | + * 启动首页频道选择 |
13 | */ | 13 | */ |
14 | public function indexAction() | 14 | public function indexAction() |
15 | { | 15 | { |
16 | // 启动滚动图 | 16 | // 启动滚动图 |
17 | - $startBannerData = Index::getBannerStart(); | 17 | + $startBannerData = IndexData::getBannerStart(); |
18 | $startBanner = array(); | 18 | $startBanner = array(); |
19 | if($startBannerData['code'] == 200) | 19 | if($startBannerData['code'] == 200) |
20 | { | 20 | { |
@@ -25,9 +25,9 @@ class IndexController extends AbstractAction | @@ -25,9 +25,9 @@ class IndexController extends AbstractAction | ||
25 | 25 | ||
26 | } | 26 | } |
27 | // 启动频道数据 | 27 | // 启动频道数据 |
28 | - $homeChannels = Index::getHomeChannels(); | 28 | + $homeChannels = IndexData::getHomeChannels(); |
29 | // 用户个人信息 | 29 | // 用户个人信息 |
30 | - $userProfile = Index::getUserProfile(0); | 30 | + $userProfile = IndexData::getUserProfile(0); |
31 | 31 | ||
32 | /*echo '<pre>'; | 32 | /*echo '<pre>'; |
33 | var_dump($homeChannels);exit;*/ | 33 | var_dump($homeChannels);exit;*/ |
1 | <?php | 1 | <?php |
2 | +use Action\AbstractAction; | ||
3 | +use LibModels\Wap\Category\BrandData; | ||
2 | 4 | ||
3 | -/* | ||
4 | - * To change this license header, choose License Headers in Project Properties. | ||
5 | - * To change this template file, choose Tools | Templates | ||
6 | - * and open the template in the editor. | 5 | +/** |
6 | + * 品牌 | ||
7 | */ | 7 | */ |
8 | +class BrandController extends AbstractAction | ||
9 | +{ | ||
10 | + public function indexAction() | ||
11 | + { | ||
12 | + // 获取品牌数据 | ||
13 | + $brandTopData = BrandData::getBrandTopData(); | ||
14 | + $brandsData = BrandData::getBrandsData(); | ||
8 | 15 | ||
16 | + $brandTop = array(); | ||
17 | + if($brandTopData['code'] == 200) | ||
18 | + { | ||
19 | + $brandTop = $brandTopData['data']; | ||
20 | + } | ||
21 | + $brands = array(); | ||
22 | + if($brandsData['code'] == 200) | ||
23 | + { | ||
24 | + $brands = $brandsData['data']; | ||
25 | + } | ||
26 | + | ||
27 | + echo '<pre>'; | ||
28 | + var_dump($brandTop, $brands);exit; | ||
29 | + | ||
30 | + $this->_view->assign('title', 'YOHO!有货'); | ||
31 | + $this->_view->display('brand', compact('brands')); | ||
32 | + } | ||
33 | +} |
1 | <?php | 1 | <?php |
2 | +use Action\AbstractAction; | ||
3 | +use LibModels\Wap\Category\ClassData; | ||
2 | 4 | ||
3 | -/* | ||
4 | - * To change this license header, choose License Headers in Project Properties. | ||
5 | - * To change this template file, choose Tools | Templates | ||
6 | - * and open the template in the editor. | 5 | +/** |
6 | + * 品牌 | ||
7 | */ | 7 | */ |
8 | +class ClassController extends AbstractAction | ||
9 | +{ | ||
10 | + public function indexAction() | ||
11 | + { | ||
12 | + $brandsData = ClassData::getClassesData(); | ||
8 | 13 | ||
14 | + $classes = array(); | ||
15 | + if($brandsData['code'] == 200) | ||
16 | + { | ||
17 | + $classes = $brandsData['data']; | ||
18 | + } | ||
19 | + | ||
20 | + echo '<pre>'; | ||
21 | + var_dump($classes);exit; | ||
22 | + | ||
23 | + $this->_view->assign('title', 'YOHO!有货'); | ||
24 | + $this->_view->display('class', compact('classes')); | ||
25 | + } | ||
26 | +} |
1 | <?php | 1 | <?php |
2 | +use Action\AbstractAction; | ||
3 | +use LibModels\Wap\Category\FocusData; | ||
2 | 4 | ||
3 | -/* | ||
4 | - * To change this license header, choose License Headers in Project Properties. | ||
5 | - * To change this template file, choose Tools | Templates | ||
6 | - * and open the template in the editor. | 5 | +/** |
6 | + * 品牌 | ||
7 | */ | 7 | */ |
8 | +class FocusController extends AbstractAction | ||
9 | +{ | ||
10 | + public function indexAction() | ||
11 | + { | ||
12 | + // 获取关注数据 | ||
13 | + $gender = $this->get('gender', '1,3'); | ||
14 | + $focusData = FocusData::getFocusData(0, $gender); | ||
8 | 15 | ||
16 | + $focus = array(); | ||
17 | + if($focusData['code'] == 200) | ||
18 | + { | ||
19 | + $focus = $focusData['data']; | ||
20 | + } | ||
21 | + | ||
22 | + echo '<pre>'; | ||
23 | + var_dump($focus);exit; | ||
24 | + | ||
25 | + $this->_view->assign('title', 'YOHO!有货'); | ||
26 | + $this->_view->display('class', compact('focus')); | ||
27 | + } | ||
28 | +} |
1 | <?php | 1 | <?php |
2 | + | ||
2 | use Action\AbstractAction; | 3 | use Action\AbstractAction; |
4 | +use Plugin\Partner\Factory; | ||
3 | 5 | ||
4 | class LoginController extends AbstractAction | 6 | class LoginController extends AbstractAction |
5 | { | 7 | { |
@@ -40,4 +42,37 @@ class LoginController extends AbstractAction | @@ -40,4 +42,37 @@ class LoginController extends AbstractAction | ||
40 | $this->_view->assign('title', '国际账号登录'); | 42 | $this->_view->assign('title', '国际账号登录'); |
41 | $this->_view->display('interational', $data); | 43 | $this->_view->display('interational', $data); |
42 | } | 44 | } |
45 | + | ||
46 | + | ||
47 | + /** | ||
48 | + * 支付宝账号登录:授权页面 | ||
49 | + */ | ||
50 | + public function alipayAction() | ||
51 | + { | ||
52 | + Factory::create('alipay')->getAuthorizeUrl(); | ||
53 | + | ||
54 | + exit(); | ||
55 | + } | ||
56 | + | ||
57 | + | ||
58 | + /** | ||
59 | + * QQ账号登录:授权页面 | ||
60 | + */ | ||
61 | + public function qqAction() | ||
62 | + { | ||
63 | + Factory::create('qqconnect')->getAuthorizeUrl(); | ||
64 | + | ||
65 | + exit(); | ||
66 | + } | ||
67 | + | ||
68 | + | ||
69 | + /** | ||
70 | + * 新浪微博账号登录:授权页面 | ||
71 | + */ | ||
72 | + public function sinaAction() | ||
73 | + { | ||
74 | + header('Location:' . Factory::create('sinaweibo')->getAuthorizeUrl()); | ||
75 | + | ||
76 | + exit(); | ||
77 | + } | ||
43 | } | 78 | } |
-
Please register or login to post a comment