Merge branch 'develop' of http://git.dev.yoho.cn/web/yohobuy.git into develop
Showing
23 changed files
with
1380 additions
and
58 deletions
@@ -518,7 +518,7 @@ class AbstractAction extends Controller_Abstract | @@ -518,7 +518,7 @@ class AbstractAction extends Controller_Abstract | ||
518 | * @param type $notModifiedExit 是否在没有修改时返回304状态 | 518 | * @param type $notModifiedExit 是否在没有修改时返回304状态 |
519 | * @return void | 519 | * @return void |
520 | */ | 520 | */ |
521 | - public static function setLastModified($modifiedTime, $notModifiedExit = true) | 521 | + public function setLastModified($modifiedTime, $notModifiedExit = true) |
522 | { | 522 | { |
523 | $modifiedTime = date('D, d M Y H:i:s ', $modifiedTime) . 'GMT'; | 523 | $modifiedTime = date('D, d M Y H:i:s ', $modifiedTime) . 'GMT'; |
524 | if ($notModifiedExit && isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $modifiedTime == $_SERVER['HTTP_IF_MODIFIED_SINCE']) { | 524 | if ($notModifiedExit && isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $modifiedTime == $_SERVER['HTTP_IF_MODIFIED_SINCE']) { |
@@ -534,11 +534,36 @@ class AbstractAction extends Controller_Abstract | @@ -534,11 +534,36 @@ class AbstractAction extends Controller_Abstract | ||
534 | * @param int $seconds 单位是秒 | 534 | * @param int $seconds 单位是秒 |
535 | * @return void | 535 | * @return void |
536 | */ | 536 | */ |
537 | - public static function setExpires($seconds = 180) | 537 | + public function setExpires($seconds = 180) |
538 | { | 538 | { |
539 | $time = date('D, d M Y H:i:s ', time() + $seconds) . 'GMT'; | 539 | $time = date('D, d M Y H:i:s ', time() + $seconds) . 'GMT'; |
540 | 540 | ||
541 | header('Expires: ' . $time); | 541 | header('Expires: ' . $time); |
542 | } | 542 | } |
543 | + | ||
544 | + /** | ||
545 | + * JS 跳转并提示 | ||
546 | + * | ||
547 | + * @param String $message 提示信息 | ||
548 | + * @param String $expression 附加的JS | ||
549 | + * @return void | ||
550 | + */ | ||
551 | + protected function helpJsRedirect($message = '', $expression = "history.back()") | ||
552 | + { | ||
553 | + header("content-type: text/html; charset=utf-8"); | ||
554 | + | ||
555 | + if ($message != '') { | ||
556 | + $message = strtr(addslashes($message), array('\n' => '\\n')); | ||
557 | + echo "<script language=\"javascript\">"; | ||
558 | + echo "alert(\"{$message}\");"; | ||
559 | + echo "</script>"; | ||
560 | + } | ||
561 | + if ($expression != '') { | ||
562 | + echo "<script language=\"javascript\">\n"; | ||
563 | + echo $expression . "\n"; | ||
564 | + echo "</script>"; | ||
565 | + } | ||
566 | + exit(); | ||
567 | + } | ||
543 | 568 | ||
544 | } | 569 | } |
@@ -109,9 +109,8 @@ class OrderData | @@ -109,9 +109,8 @@ class OrderData | ||
109 | 109 | ||
110 | /* | 110 | /* |
111 | * 支付页面的资源位 | 111 | * 支付页面的资源位 |
112 | - * To change this template file, choose Tools | Templates | ||
113 | */ | 112 | */ |
114 | - | 113 | + |
115 | public static function paymentData($gender, $yh_channel, $code) | 114 | public static function paymentData($gender, $yh_channel, $code) |
116 | { | 115 | { |
117 | //构建必传参数 | 116 | //构建必传参数 |
@@ -141,21 +140,27 @@ class OrderData | @@ -141,21 +140,27 @@ class OrderData | ||
141 | //调用接口获得数据 | 140 | //调用接口获得数据 |
142 | return Yohobuy::get(Yohobuy::SERVICE_URL . '/operations/api/v5/resource/get', $param); | 141 | return Yohobuy::get(Yohobuy::SERVICE_URL . '/operations/api/v5/resource/get', $param); |
143 | } | 142 | } |
144 | - | ||
145 | - /* | ||
146 | - * 微信支付签名 | 143 | + |
144 | + /** | ||
145 | + * 更新订单的支付方式 | ||
146 | + * | ||
147 | + * @param int $orderCode 订单号 | ||
148 | + * @param int $payment 支付方式 | ||
149 | + * @param int $uid 用户ID | ||
150 | + * @return array | ||
147 | */ | 151 | */ |
148 | - | ||
149 | - public static function weixinPaySign($orderCode) | 152 | + public static function updateOrderPayment($orderCode, $payment, $uid) |
150 | { | 153 | { |
151 | - //构建必传参数 | ||
152 | - $param['private_key'] = 'adbf5a778175ee757c34d0eba4e932bc'; | ||
153 | - $param['order_code'] = $orderCode; | ||
154 | - $param['payment_code'] = 19; | ||
155 | - $param['app_key'] = 'adbf5a778175ee75'; | 154 | + // 构建必传参数 |
155 | + $param = Yohobuy::param(); | ||
156 | + $param['method'] = 'app.SpaceOrders.updateOrdersPaymentByCode'; | ||
157 | + $param['order_code'] = (int) $orderCode; | ||
158 | + $param['payment'] = $payment; | ||
159 | + $param['uid'] = $uid; | ||
156 | $param['client_secret'] = Sign::getSign($param); | 160 | $param['client_secret'] = Sign::getSign($param); |
157 | - //调用接口获得数据 | ||
158 | - return Yohobuy::get('http://pay.yohobuy.com/payment/data.html', $param); | 161 | + |
162 | + // 调用接口获得数据 | ||
163 | + return Yohobuy::post(Yohobuy::API_URL, $param); | ||
159 | } | 164 | } |
160 | 165 | ||
161 | } | 166 | } |
library/Plugin/Pay/aliwap/AliwapConfig.php
0 → 100644
1 | +<?php | ||
2 | +namespace Plugin\Pay\aliwap; | ||
3 | + | ||
4 | +class AliwapConfig | ||
5 | +{ | ||
6 | + | ||
7 | + var $pay_url = "http://wappaygw.alipay.com/service/rest.htm?"; | ||
8 | + | ||
9 | + /** | ||
10 | + * 服务名,即时到帐为alipay.wap.trade.create. direct | ||
11 | + * Enter description here ... | ||
12 | + * @var String | ||
13 | + */ | ||
14 | + var $service = "alipay.wap.trade.create.direct"; | ||
15 | + | ||
16 | + /** | ||
17 | + * 合作伙伴在支付宝的用户ID | ||
18 | + * Enter description here ... | ||
19 | + * @var string | ||
20 | + */ | ||
21 | + var $partner = "2088701661478015"; | ||
22 | + | ||
23 | + /** | ||
24 | + * 编码 | ||
25 | + * Enter description here ... | ||
26 | + * @var String | ||
27 | + */ | ||
28 | + var $input_charset = "utf-8"; | ||
29 | + | ||
30 | + /** | ||
31 | + * 通知url,(用于后台提交) | ||
32 | + * Enter description here ... | ||
33 | + * @var String | ||
34 | + */ | ||
35 | + var $notify_url = 'http://testservice.yoho.cn:28077/payment/alipay_notify';//"http://m.yohobuy.com/shopping/pay/aliwapnotice"; | ||
36 | + | ||
37 | + /** | ||
38 | + * 浏览器的返回 | ||
39 | + * Enter description here ... | ||
40 | + * @var string | ||
41 | + */ | ||
42 | + var $return_url = "http://m.yohobuy.com/shopping/pay/aliwapreturn"; | ||
43 | + | ||
44 | + /** | ||
45 | + * 签名方式 | ||
46 | + * Enter description here ... | ||
47 | + * @var String | ||
48 | + */ | ||
49 | + var $sign_type = "MD5"; | ||
50 | + | ||
51 | + /** | ||
52 | + * 支付类型,1为购买 | ||
53 | + * Enter description here ... | ||
54 | + * @var Integer | ||
55 | + */ | ||
56 | + var $payment_type = "1"; | ||
57 | + | ||
58 | + /** | ||
59 | + * Key | ||
60 | + * Enter description here ... | ||
61 | + * @var String | ||
62 | + */ | ||
63 | + var $alipay_key = "kcxawi9bb07mzh0aq2wcirsf9znusobw"; | ||
64 | + | ||
65 | + /** | ||
66 | + * 销售者mail | ||
67 | + * Enter description here ... | ||
68 | + * @var String | ||
69 | + */ | ||
70 | + var $sellerMail = "zfb@yoho.cn"; | ||
71 | + | ||
72 | + /** | ||
73 | + * 支付不成功跳转的页面 | ||
74 | + * @var string | ||
75 | + */ | ||
76 | + var $merchant_url = 'http://m.yohobuy.com/home/orders/detail?order_code='; | ||
77 | + | ||
78 | + /** | ||
79 | + * ca证书 | ||
80 | + * @var unknown | ||
81 | + */ | ||
82 | + var $cacert = 'cacert.pem'; | ||
83 | + | ||
84 | +} |
1 | +<?php | ||
2 | +namespace Plugin\Pay\aliwap; | ||
3 | + | ||
4 | +use Plugin\Pay\aliwap\AliwapReqparams; | ||
5 | + | ||
6 | +interface AliwapInterface | ||
7 | +{ | ||
8 | + /** | ||
9 | + * 获取支付请求的url | ||
10 | + * Enter description here ... | ||
11 | + * @param Array $params | ||
12 | + */ | ||
13 | + function getPayRequestPars(AliwapReqparams $params); | ||
14 | + | ||
15 | + /** | ||
16 | + * 解析返回的参数 | ||
17 | + * Enter description here ... | ||
18 | + * @param Array $arrResponse | ||
19 | + * @return QPay_Utils_Rspparams | ||
20 | + */ | ||
21 | + function parseResponse(Array $arrResponse); | ||
22 | + | ||
23 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace Plugin\Pay\aliwap; | ||
4 | + | ||
5 | +/** | ||
6 | + * 请求付款的参数类 | ||
7 | + */ | ||
8 | +class AliwapReqparams | ||
9 | +{ | ||
10 | + | ||
11 | + public function __construct($_orderCode, $_totalFee, $_goodName, $client_ip, $_orderTime, $_paymentParameter="", $_isTest=false) | ||
12 | + { | ||
13 | + $this->orderCode = $_orderCode; | ||
14 | + $this->totalFee = $_totalFee; | ||
15 | + $this->goodsName = $_goodName; | ||
16 | + $this->spbill_create_ip = $client_ip; | ||
17 | + $this->orderTime = $_orderTime; | ||
18 | + $this->paymentParameter = $_paymentParameter; | ||
19 | + $this->isTest = $_isTest; | ||
20 | + } | ||
21 | + | ||
22 | + /** | ||
23 | + * 订单Code | ||
24 | + * Enter description here ... | ||
25 | + * @var Integer | ||
26 | + */ | ||
27 | + var $orderCode = 0; | ||
28 | + | ||
29 | + /** | ||
30 | + * 付款金额,统一采用分为单位 | ||
31 | + * Enter description here ... | ||
32 | + * @var double | ||
33 | + */ | ||
34 | + var $totalFee = 0; | ||
35 | + | ||
36 | + | ||
37 | + /** | ||
38 | + * 商品名称 | ||
39 | + * Enter description here ... | ||
40 | + * @var String | ||
41 | + */ | ||
42 | + var $goodsName = ""; | ||
43 | + | ||
44 | + /** | ||
45 | + * 客户的ip | ||
46 | + * Enter description here ... | ||
47 | + * @var Integer | ||
48 | + */ | ||
49 | + var $spbill_create_ip = ""; | ||
50 | + | ||
51 | + /** | ||
52 | + * 订单时间 | ||
53 | + * Enter description here ... | ||
54 | + * @var unknown_type | ||
55 | + */ | ||
56 | + var $orderTime = ""; | ||
57 | + | ||
58 | + /** | ||
59 | + * 支付方式参数 | ||
60 | + * Enter description here ... | ||
61 | + * @var string | ||
62 | + */ | ||
63 | + var $paymentParameter = ""; | ||
64 | + | ||
65 | + /** | ||
66 | + * 是否为测试 | ||
67 | + * Enter description here ... | ||
68 | + * @var bool | ||
69 | + */ | ||
70 | + var $isTest = false; | ||
71 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace Plugin\Pay\aliwap; | ||
4 | + | ||
5 | +/** | ||
6 | + * 回复参数 | ||
7 | + */ | ||
8 | +class AliwapRspparams | ||
9 | +{ | ||
10 | + | ||
11 | + /** | ||
12 | + * 支付结果,0为成功,1为失败 | ||
13 | + * Enter description here ... | ||
14 | + * @var Integer | ||
15 | + */ | ||
16 | + var $payResult; | ||
17 | + | ||
18 | + /** | ||
19 | + * 付款时间 | ||
20 | + * Enter description here ... | ||
21 | + * @var Integer | ||
22 | + */ | ||
23 | + var $payTime; | ||
24 | + | ||
25 | + /** | ||
26 | + * 订单Code | ||
27 | + * Enter description here ... | ||
28 | + * @var unknown_type | ||
29 | + */ | ||
30 | + var $orderCode; | ||
31 | + | ||
32 | + /** | ||
33 | + * 支付的总金额 | ||
34 | + * Enter description here ... | ||
35 | + * @var unknown_type | ||
36 | + */ | ||
37 | + var $totalFee; | ||
38 | + | ||
39 | + /** | ||
40 | + * 银行名称,中文名 | ||
41 | + * Enter description here ... | ||
42 | + * @var String | ||
43 | + */ | ||
44 | + var $bankName = ""; | ||
45 | + | ||
46 | + /** | ||
47 | + * 银行代码 | ||
48 | + * Enter description here ... | ||
49 | + * @var string | ||
50 | + */ | ||
51 | + var $bankCode = ""; | ||
52 | + | ||
53 | + /** | ||
54 | + * 结果信息 | ||
55 | + * Enter description here ... | ||
56 | + * @var string | ||
57 | + */ | ||
58 | + var $resultMsg; | ||
59 | + | ||
60 | +} |
library/Plugin/Pay/aliwap/AliwapService.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace Plugin\Pay\aliwap; | ||
4 | + | ||
5 | +use Plugin\Pay\aliwap\AliwapConfig; | ||
6 | +use Plugin\Pay\aliwap\AliwapReqparams; | ||
7 | +use Plugin\Pay\aliwap\AliwapRspparams; | ||
8 | + | ||
9 | +/** | ||
10 | + * 支付宝手机网页支付 | ||
11 | + */ | ||
12 | +class AliwapService | ||
13 | +{ | ||
14 | + | ||
15 | + var $config; | ||
16 | + var $alipay_config; | ||
17 | + | ||
18 | + public function __construct() | ||
19 | + { | ||
20 | + $this->logProjectPrefix = 'aliwap'; | ||
21 | + $this->config = new AliwapConfig(); | ||
22 | + | ||
23 | + $this->alipay_config = array( | ||
24 | + 'partner' => $this->config->partner, | ||
25 | + 'key' => $this->config->alipay_key, | ||
26 | + 'sign_type' => 'MD5', | ||
27 | + 'input_charset' => 'utf-8', | ||
28 | + 'cacert' => dirname(__FILE__) . '/cacert.pem', | ||
29 | + 'transport' => 'http' | ||
30 | + ); | ||
31 | + require_once("lib/alipay_core.function.php"); | ||
32 | + require_once("lib/alipay_rsa.function.php"); | ||
33 | + require_once("lib/alipay_md5.function.php"); | ||
34 | + require_once("lib/alipay_notify.class.php"); | ||
35 | + require_once("lib/alipay_submit.class.php"); | ||
36 | + } | ||
37 | + | ||
38 | + /** | ||
39 | + * 构造请求参数 | ||
40 | + * @see QPay_Utils_Interface::getPayRequestPars() | ||
41 | + */ | ||
42 | + public function getPayRequestPars(AliwapReqparams $params) | ||
43 | + { | ||
44 | + $para_token = array( | ||
45 | + 'service' => 'alipay.wap.trade.create.direct', | ||
46 | + 'partner' => $this->config->partner, | ||
47 | + 'sec_id' => $this->config->sign_type, | ||
48 | + 'format' => 'xml', | ||
49 | + 'v' => '2.0', | ||
50 | + 'req_id' => date('Ymdhis') . $params->orderCode, | ||
51 | + 'req_data' => $this->getTokenReqData($params->orderCode, $params->goodsName, $params->totalFee / 100), | ||
52 | + '_input_charset' => $this->config->input_charset | ||
53 | + ); | ||
54 | + //建立请求 | ||
55 | + $alipaySubmit = new \AlipaySubmit($this->alipay_config); | ||
56 | + $html_text = $alipaySubmit->buildRequestHttp($para_token); | ||
57 | + //URLDECODE返回的信息 | ||
58 | + $html_text_decode = urldecode($html_text); | ||
59 | + //解析远程模拟提交后返回的信息 | ||
60 | + $para_html_text = $alipaySubmit->parseResponse($html_text_decode); | ||
61 | + | ||
62 | + if (empty($para_html_text) || empty($para_html_text['request_token'])) { | ||
63 | + return false; | ||
64 | +// error_log("token获取失败:" . var_export($para_token, true) . "\n" . '返回结果:' . $html_text, 3, '/tmp/aliwap.log'); | ||
65 | +// throw new Exception('支付系统繁忙,请稍后再试'); | ||
66 | + } | ||
67 | + //获取request_token | ||
68 | + $request_token = $para_html_text['request_token']; | ||
69 | + //业务详细 | ||
70 | + $req_data = '<auth_and_execute_req><request_token>' . $request_token . '</request_token></auth_and_execute_req>'; | ||
71 | + //必填 | ||
72 | + //构造要请求的参数数组,无需改动 | ||
73 | + $parameter = array( | ||
74 | + "service" => "alipay.wap.auth.authAndExecute", | ||
75 | + 'partner' => $this->config->partner, | ||
76 | + 'sec_id' => $this->config->sign_type, | ||
77 | + "format" => 'xml', | ||
78 | + "v" => '2.0', | ||
79 | + "req_id" => date('Ymdhis') . $params->orderCode, | ||
80 | + "req_data" => $req_data, | ||
81 | + "_input_charset" => $this->config->input_charset | ||
82 | + ); | ||
83 | + | ||
84 | + //建立请求 | ||
85 | + $alipaySubmit = new \AlipaySubmit($this->alipay_config); | ||
86 | + $strUrl = $alipaySubmit->buildRequestUrl($parameter); | ||
87 | + return array( | ||
88 | + 'pay_url' => $this->config->pay_url, | ||
89 | + 'pars' => $strUrl, | ||
90 | + 'reqType' => 'get' | ||
91 | + ); | ||
92 | + } | ||
93 | + | ||
94 | + /** | ||
95 | + * 解析结果 | ||
96 | + * | ||
97 | + * @see AliwapInterface::parseResponse() | ||
98 | + */ | ||
99 | + public function parseResponse(Array $arrResponse) | ||
100 | + { | ||
101 | + $rsp = new AliwapRspparams(); | ||
102 | + if ($arrResponse['type'] == 'return') { | ||
103 | + //return 返回 | ||
104 | + $alipayNotify = new \AlipayNotify($this->alipay_config); | ||
105 | + $verify_result = $alipayNotify->verifyReturn(); | ||
106 | + if ($verify_result) { | ||
107 | + //商户订单号 | ||
108 | + $rsp->orderCode = $_GET['out_trade_no']; | ||
109 | + $rsp->payResult = 200; | ||
110 | + //支付宝交易号 | ||
111 | + $trade_no = $_GET['trade_no']; | ||
112 | + } else { | ||
113 | + $rsp->payResult = 400; | ||
114 | + } | ||
115 | + } else { | ||
116 | + //服务器返回 | ||
117 | + $alipayNotify = new \AlipayNotify($this->alipay_config); | ||
118 | + $verify_result = $alipayNotify->verifyNotify(); | ||
119 | + if ($verify_result) { | ||
120 | + //解密(如果是RSA签名需要解密,如果是MD5签名则下面一行清注释掉) | ||
121 | + // $notify_data = $alipayNotify->decrypt($_POST['notify_data']); | ||
122 | + //解析notify_data | ||
123 | + //注意:该功能PHP5环境及以上支持,需开通curl、SSL等PHP配置环境。建议本地调试时使用PHP开发软件 | ||
124 | + $doc = new \DOMDocument(); | ||
125 | + $doc->loadXML($_POST['notify_data']); | ||
126 | + if (!empty($doc->getElementsByTagName("notify")->item(0)->nodeValue)) { | ||
127 | + //商户订单号 | ||
128 | + $out_trade_no = $doc->getElementsByTagName("out_trade_no")->item(0)->nodeValue; | ||
129 | + //支付宝交易号 | ||
130 | + $trade_no = $doc->getElementsByTagName("trade_no")->item(0)->nodeValue; | ||
131 | + //交易状态 | ||
132 | + $trade_status = $doc->getElementsByTagName("trade_status")->item(0)->nodeValue; | ||
133 | + if ($trade_status == 'TRADE_FINISHED' || $trade_status == 'TRADE_SUCCESS') { | ||
134 | + $rsp->orderCode = $out_trade_no; | ||
135 | + $rsp->payResult = 200; | ||
136 | + } else { | ||
137 | + $rsp->payResult = 400; | ||
138 | + } | ||
139 | + } | ||
140 | + } else { | ||
141 | + $rsp->payResult = 401; | ||
142 | + } | ||
143 | + } | ||
144 | + return $rsp; | ||
145 | + } | ||
146 | + | ||
147 | + private function getTokenReqData($out_trade_no, $subject, $total_fee) | ||
148 | + { | ||
149 | + return '<direct_trade_create_req><notify_url>' . $this->config->notify_url . | ||
150 | + '</notify_url><call_back_url>' . $this->config->return_url . | ||
151 | + '</call_back_url><seller_account_name>' . $this->config->sellerMail . | ||
152 | + '</seller_account_name><out_trade_no>' . $out_trade_no . '</out_trade_no><subject>' . 'yoho order:' . $out_trade_no . | ||
153 | + '</subject><total_fee>' . $total_fee . '</total_fee><merchant_url>' . $this->config->merchant_url . $out_trade_no . | ||
154 | + '</merchant_url></direct_trade_create_req>'; | ||
155 | + } | ||
156 | + | ||
157 | +} |
library/Plugin/Pay/aliwap/cacert.pem
0 → 100644
This diff could not be displayed because it is too large.
1 | +<?php | ||
2 | + | ||
3 | +/* * | ||
4 | + * 支付宝接口公用函数 | ||
5 | + * 详细:该类是请求、通知返回两个文件所调用的公用函数核心处理文件 | ||
6 | + * 版本:3.3 | ||
7 | + * 日期:2012-07-19 | ||
8 | + * 说明: | ||
9 | + * 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。 | ||
10 | + * 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。 | ||
11 | + */ | ||
12 | + | ||
13 | +/** | ||
14 | + * 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串 | ||
15 | + * @param $para 需要拼接的数组 | ||
16 | + * return 拼接完成以后的字符串 | ||
17 | + */ | ||
18 | +function createLinkstring($para) | ||
19 | +{ | ||
20 | + $arg = ""; | ||
21 | + while (list ($key, $val) = each($para)) { | ||
22 | + $arg.=$key . "=" . $val . "&"; | ||
23 | + } | ||
24 | + //去掉最后一个&字符 | ||
25 | + $arg = substr($arg, 0, count($arg) - 2); | ||
26 | + | ||
27 | + //如果存在转义字符,那么去掉转义 | ||
28 | + if (get_magic_quotes_gpc()) { | ||
29 | + $arg = stripslashes($arg); | ||
30 | + } | ||
31 | + | ||
32 | + return $arg; | ||
33 | +} | ||
34 | + | ||
35 | +/** | ||
36 | + * 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对字符串做urlencode编码 | ||
37 | + * @param $para 需要拼接的数组 | ||
38 | + * return 拼接完成以后的字符串 | ||
39 | + */ | ||
40 | +function createLinkstringUrlencode($para) | ||
41 | +{ | ||
42 | + $arg = ""; | ||
43 | + while (list ($key, $val) = each($para)) { | ||
44 | + $arg.=$key . "=" . urlencode($val) . "&"; | ||
45 | + } | ||
46 | + //去掉最后一个&字符 | ||
47 | + $arg = substr($arg, 0, count($arg) - 2); | ||
48 | + | ||
49 | + //如果存在转义字符,那么去掉转义 | ||
50 | + if (get_magic_quotes_gpc()) { | ||
51 | + $arg = stripslashes($arg); | ||
52 | + } | ||
53 | + | ||
54 | + return $arg; | ||
55 | +} | ||
56 | + | ||
57 | +/** | ||
58 | + * 除去数组中的空值和签名参数 | ||
59 | + * @param $para 签名参数组 | ||
60 | + * return 去掉空值与签名参数后的新签名参数组 | ||
61 | + */ | ||
62 | +function paraFilter($para) | ||
63 | +{ | ||
64 | + if (isset($para['q'])) { | ||
65 | + unset($para['q']); | ||
66 | + } | ||
67 | + $para_filter = array(); | ||
68 | + while (list ($key, $val) = each($para)) { | ||
69 | + if ($key == "sign" || $key == "sign_type" || $val == "") | ||
70 | + continue; | ||
71 | + else | ||
72 | + $para_filter[$key] = $para[$key]; | ||
73 | + } | ||
74 | + return $para_filter; | ||
75 | +} | ||
76 | + | ||
77 | +/** | ||
78 | + * 对数组排序 | ||
79 | + * @param $para 排序前的数组 | ||
80 | + * return 排序后的数组 | ||
81 | + */ | ||
82 | +function argSort($para) | ||
83 | +{ | ||
84 | + ksort($para); | ||
85 | + reset($para); | ||
86 | + return $para; | ||
87 | +} | ||
88 | + | ||
89 | +/** | ||
90 | + * 写日志,方便测试(看网站需求,也可以改成把记录存入数据库) | ||
91 | + * 注意:服务器需要开通fopen配置 | ||
92 | + * @param $word 要写入日志里的文本内容 默认值:空值 | ||
93 | + */ | ||
94 | +function logResult($word = '') | ||
95 | +{ | ||
96 | + error_log("执行日期:" . strftime("%Y%m%d%H%M%S", time()) . "\n" . $word . "\n", 3, '/tmp/aliwap.log'); | ||
97 | +} | ||
98 | + | ||
99 | +/** | ||
100 | + * 远程获取数据,POST模式 | ||
101 | + * 注意: | ||
102 | + * 1.使用Crul需要修改服务器中php.ini文件的设置,找到php_curl.dll去掉前面的";"就行了 | ||
103 | + * 2.文件夹中cacert.pem是SSL证书请保证其路径有效,目前默认路径是:getcwd().'\\cacert.pem' | ||
104 | + * @param $url 指定URL完整路径地址 | ||
105 | + * @param $cacert_url 指定当前工作目录绝对路径 | ||
106 | + * @param $para 请求的数据 | ||
107 | + * @param $input_charset 编码格式。默认值:空值 | ||
108 | + * return 远程输出的数据 | ||
109 | + */ | ||
110 | +function getHttpResponsePOST($url, $cacert_url, $para, $input_charset = '') | ||
111 | +{ | ||
112 | + | ||
113 | + if (trim($input_charset) != '') { | ||
114 | + $url = $url . "_input_charset=" . $input_charset; | ||
115 | + } | ||
116 | + $curl = curl_init($url); | ||
117 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); //SSL证书认证 | ||
118 | + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); //严格认证 | ||
119 | + curl_setopt($curl, CURLOPT_CAINFO, $cacert_url); //证书地址 | ||
120 | + curl_setopt($curl, CURLOPT_HEADER, 0); // 过滤HTTP头 | ||
121 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 显示输出结果 | ||
122 | + curl_setopt($curl, CURLOPT_POST, true); // post传输数据 | ||
123 | + curl_setopt($curl, CURLOPT_POSTFIELDS, $para); // post传输数据 | ||
124 | + $responseText = curl_exec($curl); | ||
125 | + //var_dump( curl_error($curl) );//如果执行curl过程中出现异常,可打开此开关,以便查看异常内容 | ||
126 | + curl_close($curl); | ||
127 | + | ||
128 | + return $responseText; | ||
129 | +} | ||
130 | + | ||
131 | +/** | ||
132 | + * 远程获取数据,GET模式 | ||
133 | + * 注意: | ||
134 | + * 1.使用Crul需要修改服务器中php.ini文件的设置,找到php_curl.dll去掉前面的";"就行了 | ||
135 | + * 2.文件夹中cacert.pem是SSL证书请保证其路径有效,目前默认路径是:getcwd().'\\cacert.pem' | ||
136 | + * @param $url 指定URL完整路径地址 | ||
137 | + * @param $cacert_url 指定当前工作目录绝对路径 | ||
138 | + * return 远程输出的数据 | ||
139 | + */ | ||
140 | +function getHttpResponseGET($url, $cacert_url) | ||
141 | +{ | ||
142 | + $curl = curl_init($url); | ||
143 | + curl_setopt($curl, CURLOPT_HEADER, 0); // 过滤HTTP头 | ||
144 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 显示输出结果 | ||
145 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); //SSL证书认证 | ||
146 | + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); //严格认证 | ||
147 | + curl_setopt($curl, CURLOPT_CAINFO, $cacert_url); //证书地址 | ||
148 | + $responseText = curl_exec($curl); | ||
149 | + //var_dump( curl_error($curl) );//如果执行curl过程中出现异常,可打开此开关,以便查看异常内容 | ||
150 | + curl_close($curl); | ||
151 | + | ||
152 | + return $responseText; | ||
153 | +} | ||
154 | + | ||
155 | +/** | ||
156 | + * 实现多种字符编码方式 | ||
157 | + * @param $input 需要编码的字符串 | ||
158 | + * @param $_output_charset 输出的编码格式 | ||
159 | + * @param $_input_charset 输入的编码格式 | ||
160 | + * return 编码后的字符串 | ||
161 | + */ | ||
162 | +function charsetEncode($input, $_output_charset, $_input_charset) | ||
163 | +{ | ||
164 | + $output = ""; | ||
165 | + if (!isset($_output_charset)) | ||
166 | + $_output_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 | ||
174 | + die("sorry, you have no libs support for charset change."); | ||
175 | + return $output; | ||
176 | +} | ||
177 | + | ||
178 | +/** | ||
179 | + * 实现多种字符解码方式 | ||
180 | + * @param $input 需要解码的字符串 | ||
181 | + * @param $_output_charset 输出的解码格式 | ||
182 | + * @param $_input_charset 输入的解码格式 | ||
183 | + * return 解码后的字符串 | ||
184 | + */ | ||
185 | +function charsetDecode($input, $_input_charset, $_output_charset) | ||
186 | +{ | ||
187 | + $output = ""; | ||
188 | + if (!isset($_input_charset)) | ||
189 | + $_input_charset = $_input_charset; | ||
190 | + if ($_input_charset == $_output_charset || $input == null) { | ||
191 | + $output = $input; | ||
192 | + } elseif (function_exists("mb_convert_encoding")) { | ||
193 | + $output = mb_convert_encoding($input, $_output_charset, $_input_charset); | ||
194 | + } elseif (function_exists("iconv")) { | ||
195 | + $output = iconv($_input_charset, $_output_charset, $input); | ||
196 | + } else | ||
197 | + die("sorry, you have no libs support for charset changes."); | ||
198 | + return $output; | ||
199 | +} | ||
200 | + | ||
201 | +?> |
1 | +<?php | ||
2 | + | ||
3 | +/* * | ||
4 | + * MD5 | ||
5 | + * 详细:MD5加密 | ||
6 | + * 版本:3.3 | ||
7 | + * 日期:2012-07-19 | ||
8 | + * 说明: | ||
9 | + * 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。 | ||
10 | + * 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。 | ||
11 | + */ | ||
12 | + | ||
13 | +/** | ||
14 | + * 签名字符串 | ||
15 | + * @param $prestr 需要签名的字符串 | ||
16 | + * @param $key 私钥 | ||
17 | + * return 签名结果 | ||
18 | + */ | ||
19 | +function md5Sign($prestr, $key) | ||
20 | +{ | ||
21 | + $prestr = $prestr . $key; | ||
22 | + return md5($prestr); | ||
23 | +} | ||
24 | + | ||
25 | +/** | ||
26 | + * 验证签名 | ||
27 | + * @param $prestr 需要签名的字符串 | ||
28 | + * @param $sign 签名结果 | ||
29 | + * @param $key 私钥 | ||
30 | + * return 签名结果 | ||
31 | + */ | ||
32 | +function md5Verify($prestr, $sign, $key) | ||
33 | +{ | ||
34 | + $prestr = $prestr . $key; | ||
35 | + $mysgin = md5($prestr); | ||
36 | + if ($mysgin == $sign) { | ||
37 | + return true; | ||
38 | + } else { | ||
39 | + return false; | ||
40 | + } | ||
41 | +} | ||
42 | + | ||
43 | +?> |
1 | +<?php | ||
2 | + | ||
3 | +/* * | ||
4 | + * 类名:AlipayNotify | ||
5 | + * 功能:支付宝通知处理类 | ||
6 | + * 详细:处理支付宝各接口通知返回 | ||
7 | + * 版本:3.2 | ||
8 | + * 日期:2011-03-25 | ||
9 | + * 说明: | ||
10 | + * 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。 | ||
11 | + * 该代码仅供学习和研究支付宝接口使用,只是提供一个参考 | ||
12 | + | ||
13 | + * ************************注意************************* | ||
14 | + * 调试通知返回时,可查看或改写log日志的写入TXT里的数据,来检查通知返回是否正常 | ||
15 | + */ | ||
16 | + | ||
17 | +require_once("alipay_core.function.php"); | ||
18 | +require_once("alipay_rsa.function.php"); | ||
19 | +require_once("alipay_md5.function.php"); | ||
20 | + | ||
21 | +class AlipayNotify | ||
22 | +{ | ||
23 | + | ||
24 | + /** | ||
25 | + * HTTPS形式消息验证地址 | ||
26 | + */ | ||
27 | + var $https_verify_url = 'https://mapi.alipay.com/gateway.do?service=notify_verify&'; | ||
28 | + | ||
29 | + /** | ||
30 | + * HTTP形式消息验证地址 | ||
31 | + */ | ||
32 | + var $http_verify_url = 'http://notify.alipay.com/trade/notify_query.do?'; | ||
33 | + var $alipay_config; | ||
34 | + | ||
35 | + function __construct($alipay_config) | ||
36 | + { | ||
37 | + $this->alipay_config = $alipay_config; | ||
38 | + } | ||
39 | + | ||
40 | + function AlipayNotify($alipay_config) | ||
41 | + { | ||
42 | + $this->__construct($alipay_config); | ||
43 | + } | ||
44 | + | ||
45 | + /** | ||
46 | + * 针对notify_url验证消息是否是支付宝发出的合法消息 | ||
47 | + * @return 验证结果 | ||
48 | + */ | ||
49 | + function verifyNotify() | ||
50 | + { | ||
51 | + if (empty($_POST)) {//判断POST来的数组是否为空 | ||
52 | + return false; | ||
53 | + } else { | ||
54 | + | ||
55 | + //对notify_data解密 | ||
56 | + $decrypt_post_para = $_POST; | ||
57 | + if ($this->alipay_config['sign_type'] == '0001') { | ||
58 | + $decrypt_post_para['notify_data'] = rsaDecrypt($decrypt_post_para['notify_data'], $this->alipay_config['private_key_path']); | ||
59 | + } | ||
60 | + | ||
61 | + //notify_id从decrypt_post_para中解析出来(也就是说decrypt_post_para中已经包含notify_id的内容) | ||
62 | + $doc = new DOMDocument(); | ||
63 | + $doc->loadXML($decrypt_post_para['notify_data']); | ||
64 | + $notify_id = $doc->getElementsByTagName("notify_id")->item(0)->nodeValue; | ||
65 | + | ||
66 | + //生成签名结果 | ||
67 | + return $this->getSignVeryfy($decrypt_post_para, $_POST["sign"], false); | ||
68 | + //写日志记录 | ||
69 | + //if ($isSign) { | ||
70 | + // $isSignStr = 'true'; | ||
71 | + //} | ||
72 | + //else { | ||
73 | + // $isSignStr = 'false'; | ||
74 | + //} | ||
75 | + //$log_text = "responseTxt=".$responseTxt."\n notify_url_log:isSign=".$isSignStr.","; | ||
76 | + //$log_text = $log_text.createLinkString($_POST); | ||
77 | + //logResult($log_text); | ||
78 | + //验证 | ||
79 | + //$responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关 | ||
80 | + //isSign的结果不是true,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关 | ||
81 | + } | ||
82 | + } | ||
83 | + | ||
84 | + /** | ||
85 | + * 针对return_url验证消息是否是支付宝发出的合法消息 | ||
86 | + * @return 验证结果 | ||
87 | + */ | ||
88 | + function verifyReturn() | ||
89 | + { | ||
90 | + if (empty($_GET)) {//判断GET来的数组是否为空 | ||
91 | + return false; | ||
92 | + } else { | ||
93 | + //生成签名结果 | ||
94 | + $isSign = $this->getSignVeryfy($_GET, $_GET["sign"], true); | ||
95 | + //写日志记录 | ||
96 | + //if ($isSign) { | ||
97 | + // $isSignStr = 'true'; | ||
98 | + //} | ||
99 | + //else { | ||
100 | + // $isSignStr = 'false'; | ||
101 | + //} | ||
102 | + //$log_text = "return_url_log:isSign=".$isSignStr.","; | ||
103 | + //$log_text = $log_text.createLinkString($_GET); | ||
104 | + //logResult($log_text); | ||
105 | + //验证 | ||
106 | + //$responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关 | ||
107 | + //isSign的结果不是true,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关 | ||
108 | + if ($isSign) { | ||
109 | + return true; | ||
110 | + } else { | ||
111 | + return false; | ||
112 | + } | ||
113 | + } | ||
114 | + } | ||
115 | + | ||
116 | + /** | ||
117 | + * 解密 | ||
118 | + * @param $input_para 要解密数据 | ||
119 | + * @return 解密后结果 | ||
120 | + */ | ||
121 | + function decrypt($prestr) | ||
122 | + { | ||
123 | + return rsaDecrypt($prestr, trim($this->alipay_config['private_key_path'])); | ||
124 | + } | ||
125 | + | ||
126 | + /** | ||
127 | + * 异步通知时,对参数做固定排序 | ||
128 | + * @param $para 排序前的参数组 | ||
129 | + * @return 排序后的参数组 | ||
130 | + */ | ||
131 | + function sortNotifyPara($para) | ||
132 | + { | ||
133 | + $para_sort['service'] = $para['service']; | ||
134 | + $para_sort['v'] = $para['v']; | ||
135 | + $para_sort['sec_id'] = $para['sec_id']; | ||
136 | + $para_sort['notify_data'] = $para['notify_data']; | ||
137 | + return $para_sort; | ||
138 | + } | ||
139 | + | ||
140 | + /** | ||
141 | + * 获取返回时的签名验证结果 | ||
142 | + * @param $para_temp 通知返回来的参数数组 | ||
143 | + * @param $sign 返回的签名结果 | ||
144 | + * @param $isSort 是否对待签名数组排序 | ||
145 | + * @return 签名验证结果 | ||
146 | + */ | ||
147 | + function getSignVeryfy($para_temp, $sign, $isSort) | ||
148 | + { | ||
149 | + //除去待签名参数数组中的空值和签名参数 | ||
150 | + $para = paraFilter($para_temp); | ||
151 | + | ||
152 | + //对待签名参数数组排序 | ||
153 | + if ($isSort) { | ||
154 | + $para = argSort($para); | ||
155 | + } else { | ||
156 | + $para = $this->sortNotifyPara($para); | ||
157 | + } | ||
158 | + | ||
159 | + //把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串 | ||
160 | + $prestr = createLinkstring($para); | ||
161 | + $isSgin = false; | ||
162 | + switch (strtoupper(trim($this->alipay_config['sign_type']))) { | ||
163 | + case "MD5" : | ||
164 | + $isSgin = md5Verify($prestr, $sign, $this->alipay_config['key']); | ||
165 | + break; | ||
166 | + case "RSA" : | ||
167 | + $isSgin = rsaVerify($prestr, trim($this->alipay_config['ali_public_key_path']), $sign); | ||
168 | + break; | ||
169 | + case "0001" : | ||
170 | + $isSgin = rsaVerify($prestr, trim($this->alipay_config['ali_public_key_path']), $sign); | ||
171 | + break; | ||
172 | + default : | ||
173 | + $isSgin = false; | ||
174 | + } | ||
175 | + | ||
176 | + return $isSgin; | ||
177 | + } | ||
178 | + | ||
179 | + /** | ||
180 | + * 获取远程服务器ATN结果,验证返回URL | ||
181 | + * @param $notify_id 通知校验ID | ||
182 | + * @return 服务器ATN结果 | ||
183 | + * 验证结果集: | ||
184 | + * invalid命令参数不对 出现这个错误,请检测返回处理中partner和key是否为空 | ||
185 | + * true 返回正确信息 | ||
186 | + * false 请检查防火墙或者是服务器阻止端口问题以及验证时间是否超过一分钟 | ||
187 | + */ | ||
188 | + function getResponse($notify_id) | ||
189 | + { | ||
190 | + $transport = strtolower(trim($this->alipay_config['transport'])); | ||
191 | + $partner = trim($this->alipay_config['partner']); | ||
192 | + $veryfy_url = ''; | ||
193 | + if ($transport == 'https') { | ||
194 | + $veryfy_url = $this->https_verify_url; | ||
195 | + } else { | ||
196 | + $veryfy_url = $this->http_verify_url; | ||
197 | + } | ||
198 | + $veryfy_url = $veryfy_url . "partner=" . $partner . "¬ify_id=" . $notify_id; | ||
199 | + $responseTxt = getHttpResponseGET($veryfy_url, $this->alipay_config['cacert']); | ||
200 | + | ||
201 | + return $responseTxt; | ||
202 | + } | ||
203 | + | ||
204 | +} | ||
205 | + | ||
206 | +?> |
1 | +<?php | ||
2 | + | ||
3 | +/* * | ||
4 | + * 支付宝接口RSA函数 | ||
5 | + * 详细:RSA签名、验签、解密 | ||
6 | + * 版本:3.3 | ||
7 | + * 日期:2012-07-23 | ||
8 | + * 说明: | ||
9 | + * 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。 | ||
10 | + * 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。 | ||
11 | + */ | ||
12 | + | ||
13 | +/** | ||
14 | + * RSA签名 | ||
15 | + * @param $data 待签名数据 | ||
16 | + * @param $private_key_path 商户私钥文件路径 | ||
17 | + * return 签名结果 | ||
18 | + */ | ||
19 | +function rsaSign($data, $private_key_path) | ||
20 | +{ | ||
21 | + $priKey = file_get_contents($private_key_path); | ||
22 | + $res = openssl_get_privatekey($priKey); | ||
23 | + openssl_sign($data, $sign, $res); | ||
24 | + openssl_free_key($res); | ||
25 | + //base64编码 | ||
26 | + $sign = base64_encode($sign); | ||
27 | + return $sign; | ||
28 | +} | ||
29 | + | ||
30 | +/** | ||
31 | + * RSA验签 | ||
32 | + * @param $data 待签名数据 | ||
33 | + * @param $ali_public_key_path 支付宝的公钥文件路径 | ||
34 | + * @param $sign 要校对的的签名结果 | ||
35 | + * return 验证结果 | ||
36 | + */ | ||
37 | +function rsaVerify($data, $ali_public_key_path, $sign) | ||
38 | +{ | ||
39 | + $pubKey = file_get_contents($ali_public_key_path); | ||
40 | + $res = openssl_get_publickey($pubKey); | ||
41 | + $result = (bool) openssl_verify($data, base64_decode($sign), $res); | ||
42 | + openssl_free_key($res); | ||
43 | + return $result; | ||
44 | +} | ||
45 | + | ||
46 | +/** | ||
47 | + * RSA解密 | ||
48 | + * @param $content 需要解密的内容,密文 | ||
49 | + * @param $private_key_path 商户私钥文件路径 | ||
50 | + * return 解密后内容,明文 | ||
51 | + */ | ||
52 | +function rsaDecrypt($content, $private_key_path) | ||
53 | +{ | ||
54 | + $priKey = file_get_contents($private_key_path); | ||
55 | + $res = openssl_get_privatekey($priKey); | ||
56 | + //用base64将内容还原成二进制 | ||
57 | + $content = base64_decode($content); | ||
58 | + //把需要解密的内容,按128位拆开解密 | ||
59 | + $result = ''; | ||
60 | + for ($i = 0; $i < strlen($content) / 128; $i++) { | ||
61 | + $data = substr($content, $i * 128, 128); | ||
62 | + openssl_private_decrypt($data, $decrypt, $res); | ||
63 | + $result .= $decrypt; | ||
64 | + } | ||
65 | + openssl_free_key($res); | ||
66 | + return $result; | ||
67 | +} | ||
68 | + | ||
69 | +?> |
1 | +<?php | ||
2 | + | ||
3 | +/* * | ||
4 | + * 类名:AlipaySubmit | ||
5 | + * 功能:支付宝各接口请求提交类 | ||
6 | + * 详细:构造支付宝各接口表单HTML文本,获取远程HTTP数据 | ||
7 | + * 版本:3.3 | ||
8 | + * 日期:2012-07-23 | ||
9 | + * 说明: | ||
10 | + * 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。 | ||
11 | + * 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。 | ||
12 | + */ | ||
13 | +require_once("alipay_core.function.php"); | ||
14 | +require_once("alipay_rsa.function.php"); | ||
15 | +require_once("alipay_md5.function.php"); | ||
16 | + | ||
17 | +class AlipaySubmit | ||
18 | +{ | ||
19 | + | ||
20 | + var $alipay_config; | ||
21 | + | ||
22 | + /** | ||
23 | + * 支付宝网关地址 | ||
24 | + */ | ||
25 | + //var $alipay_gateway_new = 'https://mapi.alipay.com/gateway.do?'; | ||
26 | + var $alipay_gateway_new = 'http://wappaygw.alipay.com/service/rest.htm?'; | ||
27 | + | ||
28 | + function __construct($alipay_config) | ||
29 | + { | ||
30 | + $this->alipay_config = $alipay_config; | ||
31 | + } | ||
32 | + | ||
33 | + function AlipaySubmit($alipay_config) | ||
34 | + { | ||
35 | + $this->__construct($alipay_config); | ||
36 | + } | ||
37 | + | ||
38 | + /** | ||
39 | + * 生成签名结果 | ||
40 | + * @param $para_sort 已排序要签名的数组 | ||
41 | + * return 签名结果字符串 | ||
42 | + */ | ||
43 | + function buildRequestMysign($para_sort) | ||
44 | + { | ||
45 | + //把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串 | ||
46 | + $prestr = createLinkstring($para_sort); | ||
47 | + | ||
48 | + $mysign = ""; | ||
49 | + switch (strtoupper(trim($this->alipay_config['sign_type']))) { | ||
50 | + case "MD5" : | ||
51 | + $mysign = md5Sign($prestr, $this->alipay_config['key']); | ||
52 | + break; | ||
53 | + case "RSA" : | ||
54 | + $mysign = rsaSign($prestr, $this->alipay_config['private_key_path']); | ||
55 | + break; | ||
56 | + case "0001" : | ||
57 | + $mysign = rsaSign($prestr, $this->alipay_config['private_key_path']); | ||
58 | + break; | ||
59 | + default : | ||
60 | + $mysign = ""; | ||
61 | + } | ||
62 | + | ||
63 | + return $mysign; | ||
64 | + } | ||
65 | + | ||
66 | + /** | ||
67 | + * 生成要请求给支付宝的参数数组 | ||
68 | + * @param $para_temp 请求前的参数数组 | ||
69 | + * @return 要请求的参数数组 | ||
70 | + */ | ||
71 | + function buildRequestPara($para_temp) | ||
72 | + { | ||
73 | + //除去待签名参数数组中的空值和签名参数 | ||
74 | + $para_filter = paraFilter($para_temp); | ||
75 | + | ||
76 | + //对待签名参数数组排序 | ||
77 | + $para_sort = argSort($para_filter); | ||
78 | + | ||
79 | + //生成签名结果 | ||
80 | + $mysign = $this->buildRequestMysign($para_sort); | ||
81 | + | ||
82 | + //签名结果与签名方式加入请求提交参数组中 | ||
83 | + $para_sort['sign'] = $mysign; | ||
84 | + if ($para_sort['service'] != 'alipay.wap.trade.create.direct' && $para_sort['service'] != 'alipay.wap.auth.authAndExecute') { | ||
85 | + $para_sort['sign_type'] = strtoupper(trim($this->alipay_config['sign_type'])); | ||
86 | + } | ||
87 | + | ||
88 | + return $para_sort; | ||
89 | + } | ||
90 | + | ||
91 | + /** | ||
92 | + * 生成要请求给支付宝的参数数组 | ||
93 | + * @param $para_temp 请求前的参数数组 | ||
94 | + * @return 要请求的参数数组字符串 | ||
95 | + */ | ||
96 | + function buildRequestParaToString($para_temp) | ||
97 | + { | ||
98 | + //待请求参数数组 | ||
99 | + $para = $this->buildRequestPara($para_temp); | ||
100 | + | ||
101 | + //把参数组中所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对字符串做urlencode编码 | ||
102 | + $request_data = createLinkstringUrlencode($para); | ||
103 | + | ||
104 | + return $request_data; | ||
105 | + } | ||
106 | + | ||
107 | + /** | ||
108 | + * 建立请求,以表单HTML形式构造(默认) | ||
109 | + * @param $para_temp 请求参数数组 | ||
110 | + * @param $method 提交方式。两个值可选:post、get | ||
111 | + * @param $button_name 确认按钮显示文字 | ||
112 | + * @return 提交表单HTML文本 | ||
113 | + */ | ||
114 | + function buildRequestUrl($para_temp) | ||
115 | + { | ||
116 | + //待请求参数数组 | ||
117 | + $para = $this->buildRequestPara($para_temp); | ||
118 | + $urlArr = array(); | ||
119 | + foreach ($para as $k => $v) { | ||
120 | + $urlArr[] = $k . '=' . $v; | ||
121 | + } | ||
122 | + return implode('&', $urlArr); | ||
123 | + } | ||
124 | + | ||
125 | + /** | ||
126 | + * 建立请求,以模拟远程HTTP的POST请求方式构造并获取支付宝的处理结果 | ||
127 | + * @param $para_temp 请求参数数组 | ||
128 | + * @return 支付宝处理结果 | ||
129 | + */ | ||
130 | + function buildRequestHttp($para_temp) | ||
131 | + { | ||
132 | + $sResult = ''; | ||
133 | + | ||
134 | + //待请求参数数组字符串 | ||
135 | + $request_data = $this->buildRequestPara($para_temp); | ||
136 | + | ||
137 | + //远程获取数据 | ||
138 | + $sResult = getHttpResponsePOST($this->alipay_gateway_new, $this->alipay_config['cacert'], $request_data, trim(strtolower($this->alipay_config['input_charset']))); | ||
139 | + | ||
140 | + return $sResult; | ||
141 | + } | ||
142 | + | ||
143 | + /** | ||
144 | + * 建立请求,以模拟远程HTTP的POST请求方式构造并获取支付宝的处理结果,带文件上传功能 | ||
145 | + * @param $para_temp 请求参数数组 | ||
146 | + * @param $file_para_name 文件类型的参数名 | ||
147 | + * @param $file_name 文件完整绝对路径 | ||
148 | + * @return 支付宝返回处理结果 | ||
149 | + */ | ||
150 | + function buildRequestHttpInFile($para_temp, $file_para_name, $file_name) | ||
151 | + { | ||
152 | + | ||
153 | + //待请求参数数组 | ||
154 | + $para = $this->buildRequestPara($para_temp); | ||
155 | + $para[$file_para_name] = "@" . $file_name; | ||
156 | + | ||
157 | + //远程获取数据 | ||
158 | + $sResult = getHttpResponsePOST($this->alipay_gateway_new, $this->alipay_config['cacert'], $para, trim(strtolower($this->alipay_config['input_charset']))); | ||
159 | + | ||
160 | + return $sResult; | ||
161 | + } | ||
162 | + | ||
163 | + /** | ||
164 | + * 解析远程模拟提交后返回的信息 | ||
165 | + * @param $str_text 要解析的字符串 | ||
166 | + * @return 解析结果 | ||
167 | + */ | ||
168 | + function parseResponse($str_text) | ||
169 | + { | ||
170 | + //以“&”字符切割字符串 | ||
171 | + $para_split = explode('&', $str_text); | ||
172 | + //把切割后的字符串数组变成变量与数值组合的数组 | ||
173 | + foreach ($para_split as $item) { | ||
174 | + //获得第一个=字符的位置 | ||
175 | + $nPos = strpos($item, '='); | ||
176 | + //获得字符串长度 | ||
177 | + $nLen = strlen($item); | ||
178 | + //获得变量名 | ||
179 | + $key = substr($item, 0, $nPos); | ||
180 | + //获得数值 | ||
181 | + $value = substr($item, $nPos + 1, $nLen - $nPos - 1); | ||
182 | + //放入数组中 | ||
183 | + $para_text[$key] = $value; | ||
184 | + } | ||
185 | + | ||
186 | + if (!empty($para_text['res_data'])) { | ||
187 | + //解析加密部分字符串 | ||
188 | + if ($this->alipay_config['sign_type'] == '0001') { | ||
189 | + $para_text['res_data'] = rsaDecrypt($para_text['res_data'], $this->alipay_config['private_key_path']); | ||
190 | + } | ||
191 | + | ||
192 | + //token从res_data中解析出来(也就是说res_data中已经包含token的内容) | ||
193 | + $doc = new DOMDocument(); | ||
194 | + $doc->loadXML($para_text['res_data']); | ||
195 | + $para_text['request_token'] = $doc->getElementsByTagName("request_token")->item(0)->nodeValue; | ||
196 | + } | ||
197 | + | ||
198 | + return $para_text; | ||
199 | + } | ||
200 | + | ||
201 | + /** | ||
202 | + * 用于防钓鱼,调用接口query_timestamp来获取时间戳的处理函数 | ||
203 | + * 注意:该功能PHP5环境及以上支持,因此必须服务器、本地电脑中装有支持DOMDocument、SSL的PHP配置环境。建议本地调试时使用PHP开发软件 | ||
204 | + * return 时间戳字符串 | ||
205 | + */ | ||
206 | + function query_timestamp() | ||
207 | + { | ||
208 | + $url = $this->alipay_gateway_new . "service=query_timestamp&partner=" . trim(strtolower($this->alipay_config['partner'])) . "&_input_charset=" . trim(strtolower($this->alipay_config['input_charset'])); | ||
209 | + $encrypt_key = ""; | ||
210 | + | ||
211 | + $doc = new DOMDocument(); | ||
212 | + $doc->load($url); | ||
213 | + $itemEncrypt_key = $doc->getElementsByTagName("encrypt_key"); | ||
214 | + $encrypt_key = $itemEncrypt_key->item(0)->nodeValue; | ||
215 | + | ||
216 | + return $encrypt_key; | ||
217 | + } | ||
218 | + | ||
219 | +} | ||
220 | + | ||
221 | +?> |
@@ -34,7 +34,7 @@ class WxPayConfig | @@ -34,7 +34,7 @@ class WxPayConfig | ||
34 | const JS_API_CALL_URL = 'http://m.yohobuy.com/shopping/pay/wechatwap'; | 34 | const JS_API_CALL_URL = 'http://m.yohobuy.com/shopping/pay/wechatwap'; |
35 | //=======【异步通知url设置】=================================== | 35 | //=======【异步通知url设置】=================================== |
36 | //异步通知url,商户根据实际开发过程设定 | 36 | //异步通知url,商户根据实际开发过程设定 |
37 | - const NOTIFY_URL = 'http://pay.yohobuy.com/notify/wechatwap'; | 37 | + const NOTIFY_URL = 'http://testservice.yoho.cn:28077/payment/wechatwap_notify';//'http://pay.yohobuy.com/notify/wechatwap'; |
38 | //=======【证书路径设置】===================================== | 38 | //=======【证书路径设置】===================================== |
39 | /** | 39 | /** |
40 | * TODO:设置商户证书路径 | 40 | * TODO:设置商户证书路径 |
@@ -372,6 +372,16 @@ server | @@ -372,6 +372,16 @@ server | ||
372 | proxy_set_header Accept-Encoding "gzip"; | 372 | proxy_set_header Accept-Encoding "gzip"; |
373 | } | 373 | } |
374 | 374 | ||
375 | + ## since 2016/01/23 | ||
376 | + location ^~ /shopping/pay/alipay { | ||
377 | + proxy_redirect off; | ||
378 | + proxy_pass http://yohobuy; | ||
379 | + proxy_set_header Host $host; | ||
380 | + proxy_set_header X-Real-IP $remote_addr; | ||
381 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
382 | + proxy_set_header Accept-Encoding "gzip"; | ||
383 | + } | ||
384 | + | ||
375 | location / { | 385 | location / { |
376 | proxy_redirect off; | 386 | proxy_redirect off; |
377 | proxy_pass http://119.254.81.245; | 387 | proxy_pass http://119.254.81.245; |
@@ -828,7 +828,7 @@ class HomeController extends AbstractAction | @@ -828,7 +828,7 @@ class HomeController extends AbstractAction | ||
828 | 'payAppInfo' => array( | 828 | 'payAppInfo' => array( |
829 | 0 => array( | 829 | 0 => array( |
830 | 'appIcon' => '', | 830 | 'appIcon' => '', |
831 | - 'payLink' => Helpers::url('/shopping/pay/index', array('order_code' => $orderCode, 'payment_type' => 18)), | 831 | + 'payLink' => Helpers::url('/shopping/pay/alipay', array('order_code' => $orderCode, 'payment_type' => 18)), |
832 | 'appId' => 'alipay', | 832 | 'appId' => 'alipay', |
833 | 'app' => '支付宝支付', | 833 | 'app' => '支付宝支付', |
834 | 'hint' => '支付宝钱包支付', | 834 | 'hint' => '支付宝钱包支付', |
1 | +<?php | ||
2 | + | ||
3 | +use Action\AbstractAction; | ||
4 | +use Plugin\Helpers; | ||
5 | +use LibModels\Wap\Home\OrderData; | ||
6 | +use Plugin\Pay\weixin\JsApiPay; | ||
7 | +use Plugin\Pay\weixin\lib\WxPayUnifiedOrder; | ||
8 | +use Plugin\Pay\weixin\lib\WxPayApi; | ||
9 | +use Plugin\Pay\weixin\lib\WxPayConfig; | ||
10 | +use Plugin\Pay\aliwap\AliwapReqparams; | ||
11 | +use Plugin\Pay\aliwap\AliwapService; | ||
12 | + | ||
13 | +/** | ||
14 | + * 支付相关的控制器 | ||
15 | + * | ||
16 | + * @name PayController | ||
17 | + * @package Shopping | ||
18 | + * @copyright yoho.inc | ||
19 | + * @version 1.0 (2016-1-23 13:12:40) | ||
20 | + * @author fei.hong <fei.hong@yoho.cn> | ||
21 | + */ | ||
22 | +class PayController extends AbstractAction | ||
23 | +{ | ||
24 | + /** | ||
25 | + * 支付宝跳转页 | ||
26 | + * | ||
27 | + * @param int order_code 订单号 | ||
28 | + */ | ||
29 | + public function alipayAction() | ||
30 | + { | ||
31 | + do { | ||
32 | + /* 判断是否有订单号参数 */ | ||
33 | + $orderCode = $this->get('order_code'); | ||
34 | + if (empty($orderCode)) { | ||
35 | + break; | ||
36 | + } | ||
37 | + | ||
38 | + /* 判断用户是否登录 */ | ||
39 | + $uid = $this->getUid(true); | ||
40 | + if (!$uid) { | ||
41 | + $this->go( Helpers::url('/signin.html', array('refer' => $this->_request->server('HTTP_REFERER'))) ); | ||
42 | + break; | ||
43 | + } | ||
44 | + | ||
45 | + /* 判断订单信息是否存在 */ | ||
46 | + $orderDetail = OrderData::viewOrderData($orderCode, $uid, $this->_usession); | ||
47 | + if (empty($orderDetail['data'])) { | ||
48 | + $this->helpJsRedirect('没有找到该订单'); | ||
49 | + break; | ||
50 | + } | ||
51 | + | ||
52 | + /* 判断订单是否已取消 */ | ||
53 | + if (isset($orderDetail['data']['is_cancel']) && $orderDetail['data']['is_cancel'] === 'Y') { | ||
54 | + $this->helpJsRedirect('订单已经取消', 'window.location="' . Helpers::url('/home/orders/detail', array('order_code' => $orderCode)) .'";'); | ||
55 | + break; | ||
56 | + } | ||
57 | + | ||
58 | + $totalFee = $orderDetail['data']['payment_amount'] * 100; | ||
59 | + $reqParams = new AliwapReqparams($orderCode, $totalFee, '有货订单号:' . $orderCode, '', $orderDetail['data']['create_time'], '', false); | ||
60 | + $aliwapService = new AliwapService(); | ||
61 | + $payRequestPars = $aliwapService->getPayRequestPars($reqParams); | ||
62 | + if (empty($payRequestPars)) { | ||
63 | + $this->helpJsRedirect('支付系统繁忙,请稍后再试'); | ||
64 | + break; | ||
65 | + } | ||
66 | + | ||
67 | + // 记录或修改支付方式 说明:由于在web站没有支付宝手机支付的选项,这里就记录支付方式就按照web端支付宝的支付方式平台号为2 | ||
68 | + // 此处是咨询过JAVA开发任明明,按照老代码的实现方式判断,更新支付方式 | ||
69 | + $paymentRecod = OrderData::updateOrderPayment($orderCode, 2, $uid); | ||
70 | + if (empty($paymentRecod) || $paymentRecod['code'] != 200) { | ||
71 | + $this->helpJsRedirect('系统繁忙,请稍后再试'); | ||
72 | + break; | ||
73 | + } | ||
74 | + | ||
75 | + $this->go($payRequestPars['pay_url'] . $payRequestPars['pars']); | ||
76 | + } | ||
77 | + while (false); | ||
78 | + } | ||
79 | + | ||
80 | + /** | ||
81 | + * 微信支付 - 获取JSAPI参数 | ||
82 | + * | ||
83 | + * @param int order_code 订单号 | ||
84 | + * @return json | void | ||
85 | + */ | ||
86 | + public function wechatwapapiAction() | ||
87 | + { | ||
88 | + do { | ||
89 | + if (!$this->isAjax()) { | ||
90 | + break; | ||
91 | + } | ||
92 | + | ||
93 | + $uid = $this->getUid(true); | ||
94 | + if (!$uid) { | ||
95 | + break; | ||
96 | + } | ||
97 | + | ||
98 | + $orderCode = $this->get('order_code'); | ||
99 | + if (empty($orderCode)) { | ||
100 | + break; | ||
101 | + } | ||
102 | + | ||
103 | + /* 判断订单信息不存在 */ | ||
104 | + $orderDetail = OrderData::viewOrderData($orderCode, $uid, $this->_usession); | ||
105 | + if (empty($orderDetail['data'])) { | ||
106 | + break; | ||
107 | + } | ||
108 | + | ||
109 | + $totalFee = strval($orderDetail['data']['payment_amount'] * 100); | ||
110 | + $openId = $this->getSession('weixinOpenId'); | ||
111 | + if (empty($openId)) { | ||
112 | + break; | ||
113 | + } | ||
114 | + | ||
115 | + //统一下单 | ||
116 | + $tools = new JsApiPay(); | ||
117 | + $input = new WxPayUnifiedOrder(); | ||
118 | + $input->SetBody('有货订单号:' . $orderCode); | ||
119 | + $input->SetOut_trade_no('YOHOBuy_' . $orderCode); // 商户订单号 | ||
120 | + $input->SetTotal_fee($totalFee); | ||
121 | + $input->SetTime_start(date("YmdHis", (int) $orderDetail['data']['create_time'])); | ||
122 | + $input->SetTime_expire(date("YmdHis", (int) $orderDetail['data']['create_time'] + 7200)); | ||
123 | + $input->SetNotify_url(WxPayConfig::NOTIFY_URL); | ||
124 | + $input->SetTrade_type("JSAPI"); | ||
125 | + $input->SetOpenid($openId); | ||
126 | + $order = WxPayApi::unifiedOrder($input); | ||
127 | + $jsApiParameters = $tools->GetJsApiParameters($order); | ||
128 | + | ||
129 | + $this->echoJson(array('code' => 200, 'data' => array('jsApiParameters' => json_decode($jsApiParameters)))); | ||
130 | + | ||
131 | + } while (false); | ||
132 | + } | ||
133 | + | ||
134 | + | ||
135 | +} |
@@ -4,7 +4,7 @@ application.directory = APPLICATION_PATH "/application" | @@ -4,7 +4,7 @@ application.directory = APPLICATION_PATH "/application" | ||
4 | ;;website library | 4 | ;;website library |
5 | application.library = ROOT_PATH "/library" | 5 | application.library = ROOT_PATH "/library" |
6 | ;;模块配置 | 6 | ;;模块配置 |
7 | -application.modules = "Index,Category,Channel,Guang,Passport,Product,Cart" | 7 | +application.modules = "Index,Category,Channel,Guang,Passport,Product,Cart,Shopping" |
8 | ;;加载 | 8 | ;;加载 |
9 | application.bootstrap = APPLICATION_PATH "/application/Bootstrap.php" | 9 | application.bootstrap = APPLICATION_PATH "/application/Bootstrap.php" |
10 | ;;view文件的扩展名 | 10 | ;;view文件的扩展名 |
@@ -4,7 +4,7 @@ application.directory = APPLICATION_PATH "/application" | @@ -4,7 +4,7 @@ application.directory = APPLICATION_PATH "/application" | ||
4 | ;;website library | 4 | ;;website library |
5 | application.library = ROOT_PATH "/library" | 5 | application.library = ROOT_PATH "/library" |
6 | ;;默认模块 | 6 | ;;默认模块 |
7 | -application.modules = "Index,Category,Channel,Guang,Passport,Product,Cart" | 7 | +application.modules = "Index,Category,Channel,Guang,Passport,Product,Cart,Shopping" |
8 | ;;加载 | 8 | ;;加载 |
9 | application.bootstrap = APPLICATION_PATH "/application/Bootstrap.php" | 9 | application.bootstrap = APPLICATION_PATH "/application/Bootstrap.php" |
10 | ;;view文件的扩展名 | 10 | ;;view文件的扩展名 |
@@ -4,7 +4,7 @@ application.directory = APPLICATION_PATH "/application" | @@ -4,7 +4,7 @@ application.directory = APPLICATION_PATH "/application" | ||
4 | ;;website library | 4 | ;;website library |
5 | application.library = ROOT_PATH "/library" | 5 | application.library = ROOT_PATH "/library" |
6 | ;;默认模块 | 6 | ;;默认模块 |
7 | -application.modules = "Index,Category,Channel,Guang,Passport,Product,Cart" | 7 | +application.modules = "Index,Category,Channel,Guang,Passport,Product,Cart,Shopping" |
8 | ;;加载 | 8 | ;;加载 |
9 | application.bootstrap = APPLICATION_PATH "/application/Bootstrap.php" | 9 | application.bootstrap = APPLICATION_PATH "/application/Bootstrap.php" |
10 | ;;view文件的扩展名 | 10 | ;;view文件的扩展名 |
@@ -4,7 +4,7 @@ application.directory = APPLICATION_PATH "/application" | @@ -4,7 +4,7 @@ application.directory = APPLICATION_PATH "/application" | ||
4 | ;;website library | 4 | ;;website library |
5 | application.library = ROOT_PATH "/library" | 5 | application.library = ROOT_PATH "/library" |
6 | ;;默认模块 | 6 | ;;默认模块 |
7 | -application.modules = "Index,Category,Channel,Guang,Passport,Product,Cart" | 7 | +application.modules = "Index,Category,Channel,Guang,Passport,Product,Cart,Shopping" |
8 | ;;加载 | 8 | ;;加载 |
9 | application.bootstrap = APPLICATION_PATH "/application/Bootstrap.php" | 9 | application.bootstrap = APPLICATION_PATH "/application/Bootstrap.php" |
10 | ;;view文件的扩展名 | 10 | ;;view文件的扩展名 |
@@ -2,6 +2,8 @@ | @@ -2,6 +2,8 @@ | ||
2 | 2 | ||
3 | use Action\WebAction; | 3 | use Action\WebAction; |
4 | use Product\BrandsModel; | 4 | use Product\BrandsModel; |
5 | +use LibModels\Web\Product\SearchData; | ||
6 | +use Plugin\Helpers; | ||
5 | 7 | ||
6 | /** | 8 | /** |
7 | * 品牌首页 | 9 | * 品牌首页 |
@@ -33,8 +35,7 @@ class BrandsController extends WebAction | @@ -33,8 +35,7 @@ class BrandsController extends WebAction | ||
33 | /** | 35 | /** |
34 | * 品牌接口数据 | 36 | * 品牌接口数据 |
35 | * | 37 | * |
36 | - * @param | ||
37 | - * string id 获取品牌ID | 38 | + * @param string brandId 获取品牌ID |
38 | * @return json | 39 | * @return json |
39 | */ | 40 | */ |
40 | public function brandinfoAction() | 41 | public function brandinfoAction() |
@@ -8,6 +8,8 @@ use LibModels\Web\Product\BrandData; | @@ -8,6 +8,8 @@ use LibModels\Web\Product\BrandData; | ||
8 | use Index\HomeModel; | 8 | use Index\HomeModel; |
9 | use Product\SearchModel; | 9 | use Product\SearchModel; |
10 | use WebPlugin\Helpers; | 10 | use WebPlugin\Helpers; |
11 | +use Plugin\Images; | ||
12 | +use LibModels\Web\Product\SearchData; | ||
11 | 13 | ||
12 | /** | 14 | /** |
13 | * 品牌首页模板数据模型 | 15 | * 品牌首页模板数据模型 |
@@ -46,11 +48,7 @@ class BrandsModel | @@ -46,11 +48,7 @@ class BrandsModel | ||
46 | 48 | ||
47 | return $data; | 49 | return $data; |
48 | } | 50 | } |
49 | - | ||
50 | - | ||
51 | - | ||
52 | - | ||
53 | - | 51 | + |
54 | /** | 52 | /** |
55 | * 品牌介绍页 | 53 | * 品牌介绍页 |
56 | * @param array $customCondition | 54 | * @param array $customCondition |
@@ -62,43 +60,39 @@ class BrandsModel | @@ -62,43 +60,39 @@ class BrandsModel | ||
62 | $urlList = array(); | 60 | $urlList = array(); |
63 | //组合搜索品牌url | 61 | //组合搜索品牌url |
64 | $urlList['brand'] = HelperSearch::getBrandUrl($customOptions); | 62 | $urlList['brand'] = HelperSearch::getBrandUrl($customOptions); |
65 | - | 63 | + |
66 | //批量调接口 | 64 | //批量调接口 |
67 | $result = Yohobuy::getMulti($urlList, array(), true); | 65 | $result = Yohobuy::getMulti($urlList, array(), true); |
68 | - | 66 | + |
69 | if (isset($result['brand'])) { | 67 | if (isset($result['brand'])) { |
70 | $banner = HelperSearch::getBannerFormat($result['brand'], $customOptions['brandBanner']); | 68 | $banner = HelperSearch::getBannerFormat($result['brand'], $customOptions['brandBanner']); |
71 | } | 69 | } |
72 | - | 70 | + |
73 | return array( | 71 | return array( |
74 | 'brandBanner' => $banner, | 72 | 'brandBanner' => $banner, |
75 | 'brandAbout' => $customOptions['brandAbout'] | 73 | 'brandAbout' => $customOptions['brandAbout'] |
76 | ); | 74 | ); |
77 | } | 75 | } |
78 | - | 76 | + |
79 | //根据品牌域名处理相关品牌参数 | 77 | //根据品牌域名处理相关品牌参数 |
80 | public static function getBrandByDomain($domain, $fields) | 78 | public static function getBrandByDomain($domain, $fields) |
81 | - { | 79 | + { |
82 | $brandInfo = BrandData::getBrandLogoByDomain($domain, $fields); | 80 | $brandInfo = BrandData::getBrandLogoByDomain($domain, $fields); |
83 | $result = array(); | 81 | $result = array(); |
84 | if (!empty($brandInfo['data']) && $brandInfo['code'] == 200) { | 82 | if (!empty($brandInfo['data']) && $brandInfo['code'] == 200) { |
85 | $result['brandId'] = isset($brandInfo['data']['id']) ? $brandInfo['data']['id'] : ''; | 83 | $result['brandId'] = isset($brandInfo['data']['id']) ? $brandInfo['data']['id'] : ''; |
86 | $result['node'] = isset($brandInfo['data']['static_content_code']) ? $brandInfo['data']['static_content_code'] : false; | 84 | $result['node'] = isset($brandInfo['data']['static_content_code']) ? $brandInfo['data']['static_content_code'] : false; |
87 | - $result['brandBanner'] = isset($brandInfo['data']['brand_banner']) ? $brandInfo['data']['brand_banner']: ''; | 85 | + $result['brandBanner'] = isset($brandInfo['data']['brand_banner']) ? $brandInfo['data']['brand_banner'] : ''; |
88 | $result['brandNameEn'] = isset($brandInfo['data']['brand_name_en']) ? $brandInfo['data']['brand_name_en'] : ''; | 86 | $result['brandNameEn'] = isset($brandInfo['data']['brand_name_en']) ? $brandInfo['data']['brand_name_en'] : ''; |
89 | $result['brandNameCn'] = isset($brandInfo['data']['brand_name_cn']) ? $brandInfo['data']['brand_name_cn'] : ''; | 87 | $result['brandNameCn'] = isset($brandInfo['data']['brand_name_cn']) ? $brandInfo['data']['brand_name_cn'] : ''; |
90 | $result['brandAbout'] = isset($brandInfo['data']['brand_intro']) ? $brandInfo['data']['brand_intro'] : ''; | 88 | $result['brandAbout'] = isset($brandInfo['data']['brand_intro']) ? $brandInfo['data']['brand_intro'] : ''; |
91 | - } else { | 89 | + } |
90 | + else { | ||
92 | return false; | 91 | return false; |
93 | } | 92 | } |
94 | return $result; | 93 | return $result; |
95 | } | 94 | } |
96 | - | ||
97 | - | ||
98 | - | ||
99 | - | ||
100 | - | ||
101 | - | 95 | + |
102 | //获取品牌系列数据 | 96 | //获取品牌系列数据 |
103 | public static function getAdNav($brandId, $status = 1) | 97 | public static function getAdNav($brandId, $status = 1) |
104 | { | 98 | { |
@@ -141,14 +135,13 @@ class BrandsModel | @@ -141,14 +135,13 @@ class BrandsModel | ||
141 | 135 | ||
142 | //组合用户浏览记录url | 136 | //组合用户浏览记录url |
143 | //$urlList['reviewUrl'] = HelperSearch::getReviewUrl($searchCondition['condition']); | 137 | //$urlList['reviewUrl'] = HelperSearch::getReviewUrl($searchCondition['condition']); |
144 | - | ||
145 | //批量调接口 | 138 | //批量调接口 |
146 | $result = Yohobuy::getMulti($urlList, array(), true); | 139 | $result = Yohobuy::getMulti($urlList, array(), true); |
147 | - | 140 | + |
148 | //组织模板数据格式 | 141 | //组织模板数据格式 |
149 | $data = HelperSearch::getList($result, $searchCondition['options']); | 142 | $data = HelperSearch::getList($result, $searchCondition['options']); |
150 | 143 | ||
151 | - | 144 | + |
152 | return $data; | 145 | return $data; |
153 | } | 146 | } |
154 | 147 | ||
@@ -206,9 +199,9 @@ class BrandsModel | @@ -206,9 +199,9 @@ class BrandsModel | ||
206 | $brandList[$lk] = $listTmp; | 199 | $brandList[$lk] = $listTmp; |
207 | } | 200 | } |
208 | //将brandList里的0-9 排序到最后 | 201 | //将brandList里的0-9 排序到最后 |
209 | - $numBrand['0~9']=$brandList['0~9']; | ||
210 | - unset($brandList['0~9']); | ||
211 | - $brandList+=$numBrand; | 202 | + $numBrand['0~9'] = $brandList['0~9']; |
203 | + unset($brandList['0~9']); | ||
204 | + $brandList+=$numBrand; | ||
212 | } | 205 | } |
213 | return array( | 206 | return array( |
214 | 'brandTop' => $brandTop, | 207 | 'brandTop' => $brandTop, |
@@ -219,30 +212,48 @@ class BrandsModel | @@ -219,30 +212,48 @@ class BrandsModel | ||
219 | /* | 212 | /* |
220 | * 获取单个广告浮窗内容 | 213 | * 获取单个广告浮窗内容 |
221 | */ | 214 | */ |
215 | + | ||
222 | public static function getBrandInfo($brandId, $uid) | 216 | public static function getBrandInfo($brandId, $uid) |
223 | { | 217 | { |
224 | $data = array(); | 218 | $data = array(); |
219 | + $imgs = array(); | ||
220 | + //获取品牌简介 | ||
225 | $res = BrandData::getBrandIntro($brandId, $uid); | 221 | $res = BrandData::getBrandIntro($brandId, $uid); |
226 | - $condition = array( | ||
227 | - 'viewNum'=>3, | ||
228 | - '' | ||
229 | - ); | ||
230 | - \LibModels\Web\Product\SearchData::searchElasticByCondition($condition); | ||
231 | if (isset($res['data']) && $res['data']) { | 222 | if (isset($res['data']) && $res['data']) { |
232 | - $icoUrlTmp = explode("?", $res['data']['brand_ico']) ; | 223 | + //获取品牌下的产品信息 |
224 | + $proInfo = self::getProductByBrand($brandId); | ||
225 | + $proInfoTmp = $proInfo['data']['product_list']; | ||
226 | + if (isset($proInfoTmp) && $proInfoTmp) { | ||
227 | + foreach ($proInfoTmp as $v) { | ||
228 | + $imgs[] = array( | ||
229 | + 'src' => Images::getImageUrl($v['default_images'], 80, 100, 3, 'goodsimg') | ||
230 | + ); | ||
231 | + } | ||
232 | + } | ||
233 | + //整合 | ||
233 | $data = array( | 234 | $data = array( |
234 | 'key' => $res['data']['brand_id'], | 235 | 'key' => $res['data']['brand_id'], |
235 | - 'icon' => $icoUrlTmp[0], | ||
236 | - 'title' => $res['data']['brand_name'], | ||
237 | - 'content' =>$res['data']['brand_intro'], | 236 | + 'icon' => Helpers::getImageUrl($res['data']['brand_ico'], 80, 50, 3), |
237 | + 'title' => $res['data']['brand_name'], | ||
238 | + 'content' => $res['data']['brand_intro'], | ||
238 | 'subtitle' => 'FEATURED ITEMS', | 239 | 'subtitle' => 'FEATURED ITEMS', |
239 | - 'imgs' => array(), | 240 | + 'imgs' => $imgs |
240 | ); | 241 | ); |
241 | } | 242 | } |
242 | return $data; | 243 | return $data; |
243 | } | 244 | } |
244 | 245 | ||
245 | /* | 246 | /* |
247 | + * 根据brandId获取产品信息 | ||
248 | + */ | ||
249 | + public static function getProductByBrand($brandId, $num = 3) | ||
250 | + { | ||
251 | + $condition['viewNum'] = $num; | ||
252 | + $condition['brand'] = $brandId; | ||
253 | + return searchData::searchElasticByCondition($condition); | ||
254 | + } | ||
255 | + | ||
256 | + /* | ||
246 | * 获取品牌一览资源位&channelType | 257 | * 获取品牌一览资源位&channelType |
247 | */ | 258 | */ |
248 | 259 |
-
Please register or login to post a comment