Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zuiketang
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
zuiketang
Commits
6cced394
Commit
6cced394
authored
Oct 13, 2016
by
xiabin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
支付部分
parent
af5c2ab8
Changes
21
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
1680 additions
and
12 deletions
+1680
-12
params.php
src/common/config/params.php
+28
-1
Utils.php
src/common/libs/Utils.php
+44
-0
WeixinPay.php
src/common/libs/WeixinPay.php
+108
-0
AliPay.php
src/common/libs/alipay/AliPay.php
+146
-0
AlipayNotify.php
src/common/libs/alipay/AlipayNotify.php
+162
-0
alipay_core.function.php
src/common/libs/alipay/libs/alipay_core.function.php
+176
-0
alipay_md5.function.php
src/common/libs/alipay/libs/alipay_md5.function.php
+41
-0
alipay_notify.class.php
src/common/libs/alipay/libs/alipay_notify.class.php
+163
-0
alipay_submit.class.php
src/common/libs/alipay/libs/alipay_submit.class.php
+130
-0
Course.php
src/common/models/Course.php
+23
-0
Orders.php
src/common/models/Orders.php
+21
-1
composer.json
src/composer.json
+3
-1
composer.lock
src/composer.lock
+104
-2
HomeController.php
src/frontend/controllers/HomeController.php
+140
-4
PayController.php
src/frontend/controllers/PayController.php
+278
-0
TestController.php
src/frontend/controllers/TestController.php
+92
-0
index.php
src/frontend/views/home/index.php
+0
-1
index.php
src/frontend/views/test/index.php
+11
-0
info.php
src/frontend/views/user-center/info.php
+1
-1
index.js
src/frontend/web/js/home/index.js
+1
-1
test.php
src/test.php
+8
-0
No files found.
src/common/config/params.php
View file @
6cced394
...
@@ -9,5 +9,32 @@ return [
...
@@ -9,5 +9,32 @@ return [
'msg.userid'
=>
'78'
,
'msg.userid'
=>
'78'
,
'msg.account'
=>
'276147613x'
,
'msg.account'
=>
'276147613x'
,
'msg.password'
=>
'276147613'
,
'msg.password'
=>
'276147613'
,
'msg.signature'
=>
'【最课堂】'
'msg.signature'
=>
'【最课堂】'
,
'alipay'
=>
[
'partner'
=>
'2088701843067550'
,
'seller_id'
=>
'2088701843067550'
,
'key'
=>
'12vr33u4g314hytde3g81oao9dfdarm6'
,
'notify_url'
=>
'http://商户网址/create_direct_pay_by_user-PHP-UTF-8/notify_url.php'
,
'return_url'
=>
'http://商户网址/create_direct_pay_by_user-PHP-UTF-8/return_url.php'
,
'sign_type'
=>
strtoupper
(
'MD5'
),
'input_charset'
=>
strtolower
(
'utf-8'
),
'cacert'
=>
getcwd
()
.
'\\cacert.pem'
,
'transport'
=>
'http'
,
'payment_type'
=>
'1'
,
'service'
=>
'create_direct_pay_by_user'
,
],
// 'weixinpay'=>[
// 'appid'=>'wx180521eb22e9d7af',
// 'mchid'=>'1295461001',
// 'key'=>'ejg0l9phOAkp021qB54shz0Q8Tiscwzy',
// 'appsecret'=>'f20293c9548c469fb8b855fc98c4ef3c',
//
// ]
'weixinpay'
=>
[
'appid'
=>
'wx5714a24a60083b2a'
,
'mchid'
=>
'1399794002'
,
'key'
=>
'8934e7d15453e97507ef794cf7b0519d'
,
'appsecret'
=>
'7c18222c6ec31efa65d21606a629585d'
,
]
];
];
src/common/libs/Utils.php
View file @
6cced394
...
@@ -110,4 +110,48 @@ class Utils
...
@@ -110,4 +110,48 @@ class Utils
return
$count
;
return
$count
;
}
}
/**
* @param $rootElementName
* @param $ar
* @return mixed
*/
public
static
function
assocArrayToXML
(
$rootElementName
,
$ar
)
{
if
(
$rootElementName
===
NULL
)
{
$xml
=
new
\SimpleXMLElement
(
"<?xml version=
\"
1.0
\"
?>"
);
}
else
{
$xml
=
new
\SimpleXMLElement
(
"<?xml version=
\"
1.0
\"
?><
{
$rootElementName
}
></
{
$rootElementName
}
>"
);
}
$f
=
create_function
(
'$f,$c,$a'
,
'
foreach($a as $k=>$v) {
if(is_array($v)) {
$ch=$c->addChild($k);
$f($f,$ch,$v);
} else {
$c->addChild($k,$v);
}
}'
);
$f
(
$f
,
$xml
,
$ar
);
return
$xml
->
asXML
();
}
/**
* xml to array
* @param $xml
* @return bool|mixed
*/
public
static
function
xmlToArray
(
$xml
)
{
if
(
!
$xml
)
{
return
FALSE
;
}
//将XML转为array
//禁止引用外部xml实体
libxml_disable_entity_loader
(
TRUE
);
return
json_decode
(
json_encode
(
simplexml_load_string
(
$xml
,
'SimpleXMLElement'
,
LIBXML_NOCDATA
)),
TRUE
);
}
}
}
\ No newline at end of file
src/common/libs/WeixinPay.php
0 → 100644
View file @
6cced394
<?php
/**
* Created by PhpStorm.
* User: xiabin
* Date: 2016/10/13
* Time: 下午4:51
*/
namespace
common\libs
;
use
dosamigos\qrcode\formats\Wifi
;
class
WeixinPay
{
const
UNIFIEDORDER
=
'https://api.mch.weixin.qq.com/pay/unifiedorder'
;
const
NOTIFY_URL
=
"http://c.pp.cc/pay/weixin-notify"
;
private
$appid
;
private
$mchid
;
private
$appsecret
;
private
$key
;
private
static
$instance
=
NULL
;
public
function
__construct
(
$appid
,
$mchid
,
$appsecret
,
$key
)
{
$this
->
appid
=
$appid
;
$this
->
mchid
=
$mchid
;
$this
->
appsecret
=
$appsecret
;
$this
->
key
=
$key
;
}
/**
* @return WeixinPay|null
*/
public
static
function
getInstance
()
{
if
(
self
::
$instance
===
NULL
)
{
$weixinpay
=
\Yii
::
$app
->
params
[
'weixinpay'
];
self
::
$instance
=
new
WeixinPay
(
$weixinpay
[
'appid'
],
$weixinpay
[
'mchid'
],
$weixinpay
[
'appsecret'
],
$weixinpay
[
'key'
]
);
}
return
self
::
$instance
;
}
/**
* 生成微信支付url
* @param $productId
* @return string
*/
public
function
makePayUrl
(
$productId
)
{
$data
=
[
'appid'
=>
$this
->
appid
,
'mch_id'
=>
$this
->
mchid
,
'time_stamp'
=>
time
(),
'nonce_str'
=>
\Yii
::
$app
->
security
->
generateRandomString
(
16
),
'sign'
=>
''
,
'product_id'
=>
$productId
];
$data
[
'sign'
]
=
self
::
makeWeixinPaySign
(
$data
,
$this
->
key
);
return
"weixin://wxpay/bizpayurl?"
.
self
::
toUrlParams
(
$data
,
TRUE
);
}
/**
* @param $data
* @param $key
* @return string
*/
public
static
function
makeWeixinPaySign
(
$data
,
$key
)
{
//签名步骤一:按字典序排序参数
ksort
(
$data
);
$string
=
self
::
toUrlParams
(
$data
);
//签名步骤二:在string后加入KEY
$string
=
$string
.
"&key="
.
$key
;
//签名步骤三:MD5加密
$string
=
md5
(
$string
);
//签名步骤四:所有字符转为大写
$result
=
strtoupper
(
$string
);
return
$result
;
}
/**
* @param $data
* @param bool $signFliter 默认过滤sign true 不过滤
* @return string
*/
private
static
function
toUrlParams
(
$data
,
$signFliter
=
FALSE
)
{
$buff
=
""
;
foreach
(
$data
as
$k
=>
$v
)
{
if
((
$signFliter
or
$k
!=
"sign"
)
&&
$v
!=
""
&&
!
is_array
(
$v
))
{
$buff
.=
$k
.
"="
.
$v
.
"&"
;
}
}
$buff
=
trim
(
$buff
,
"&"
);
return
$buff
;
}
}
\ No newline at end of file
src/common/libs/alipay/AliPay.php
0 → 100644
View file @
6cced394
<?php
/**
* Created by PhpStorm.
* User: xiabin
* Date: 2016/10/12
* Time: 上午10:24
*/
namespace
common\libs\alipay
;
use
DOMDocument
;
use
yii\helpers\ArrayHelper
;
require_once
(
dirname
(
__FILE__
)
.
"/libs/alipay_core.function.php"
);
require_once
(
dirname
(
__FILE__
)
.
"/libs/alipay_md5.function.php"
);
class
AliPay
{
private
$alipay_config
;
/**
*支付宝网关地址(新)
*/
private
$alipay_gateway_new
=
'https://mapi.alipay.com/gateway.do?'
;
public
function
__construct
()
{
$this
->
alipay_config
=
\Yii
::
$app
->
params
[
'alipay'
];
}
/**
* 生成签名结果
* @param $para_sort 已排序要签名的数组
* @return string
*/
function
buildRequestMysign
(
$para_sort
)
{
//把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
$prestr
=
createLinkstring
(
$para_sort
);
$mysign
=
""
;
switch
(
strtoupper
(
trim
(
$this
->
alipay_config
[
'sign_type'
])))
{
case
"MD5"
:
$mysign
=
md5Sign
(
$prestr
,
$this
->
alipay_config
[
'key'
]);
break
;
default
:
$mysign
=
""
;
}
return
$mysign
;
}
/**
* 生成要请求给支付宝的参数数组
* @param $para_temp 请求前的参数数组
* @return 要请求的参数数组
*/
function
buildRequestPara
(
$para_temp
)
{
//除去待签名参数数组中的空值和签名参数
$para_filter
=
paraFilter
(
$para_temp
);
//对待签名参数数组排序
$para_sort
=
argSort
(
$para_filter
);
//生成签名结果
$mysign
=
$this
->
buildRequestMysign
(
$para_sort
);
//签名结果与签名方式加入请求提交参数组中
$para_sort
[
'sign'
]
=
$mysign
;
$para_sort
[
'sign_type'
]
=
strtoupper
(
trim
(
$this
->
alipay_config
[
'sign_type'
]));
return
$para_sort
;
}
/**
* 生成要请求给支付宝的参数数组
* @param $para_temp 请求前的参数数组
* @return 要请求的参数数组字符串
*/
function
buildRequestParaToString
(
$para_temp
)
{
//待请求参数数组
$para
=
$this
->
buildRequestPara
(
$para_temp
);
//把参数组中所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对字符串做urlencode编码
$request_data
=
createLinkstringUrlencode
(
$para
);
return
$request_data
;
}
/**
* 建立请求,以表单HTML形式构造(默认)
* @param $para_temp 请求参数数组
* @param $method 提交方式。两个值可选:post、get
* @param $button_name 确认按钮显示文字
* @return 提交表单HTML文本
*/
function
buildRequestForm
(
$para_temp
,
$method
,
$button_name
)
{
//待请求参数数组
$para_temp
=
ArrayHelper
::
merge
([
"service"
=>
$this
->
alipay_config
[
'service'
],
"partner"
=>
$this
->
alipay_config
[
'partner'
],
"seller_id"
=>
$this
->
alipay_config
[
'seller_id'
],
"payment_type"
=>
$this
->
alipay_config
[
'payment_type'
],
"return_url"
=>
$this
->
alipay_config
[
'return_url'
],
"_input_charset"
=>
trim
(
strtolower
(
$this
->
alipay_config
[
'input_charset'
]))
],
$para_temp
);
$para
=
$this
->
buildRequestPara
(
$para_temp
);
$sHtml
=
"<form id='alipaysubmit' name='alipaysubmit' action='"
.
$this
->
alipay_gateway_new
.
"_input_charset="
.
trim
(
strtolower
(
$this
->
alipay_config
[
'input_charset'
]))
.
"' method='"
.
$method
.
"'>"
;
while
(
list
(
$key
,
$val
)
=
each
(
$para
))
{
$sHtml
.=
"<input type='hidden' name='"
.
$key
.
"' value='"
.
$val
.
"'/>"
;
}
//submit按钮控件请不要含有name属性
$sHtml
=
$sHtml
.
"<input type='submit' value='"
.
$button_name
.
"' style='display:none;'></form>"
;
$sHtml
=
$sHtml
.
"<script>document.forms['alipaysubmit'].submit();</script>"
;
return
$sHtml
;
}
/**
* 用于防钓鱼,调用接口query_timestamp来获取时间戳的处理函数
* 注意:该功能PHP5环境及以上支持,因此必须服务器、本地电脑中装有支持DOMDocument、SSL的PHP配置环境。建议本地调试时使用PHP开发软件
* return 时间戳字符串
*/
function
query_timestamp
()
{
$url
=
$this
->
alipay_gateway_new
.
"service=query_timestamp&partner="
.
trim
(
strtolower
(
$this
->
alipay_config
[
'partner'
]))
.
"&_input_charset="
.
trim
(
strtolower
(
$this
->
alipay_config
[
'input_charset'
]));
$encrypt_key
=
""
;
$doc
=
new
DOMDocument
();
$doc
->
load
(
$url
);
$itemEncrypt_key
=
$doc
->
getElementsByTagName
(
"encrypt_key"
);
$encrypt_key
=
$itemEncrypt_key
->
item
(
0
)
->
nodeValue
;
return
$encrypt_key
;
}
}
\ No newline at end of file
src/common/libs/alipay/AlipayNotify.php
0 → 100644
View file @
6cced394
<?php
/**
* Created by PhpStorm.
* User: xiabin
* Date: 2016/10/12
* Time: 下午3:52
*/
namespace
common\libs\alipay
;
class
AlipayNotify
{
/**
* HTTPS形式消息验证地址
*/
private
$https_verify_url
=
'https://mapi.alipay.com/gateway.do?service=notify_verify&'
;
/**
* HTTP形式消息验证地址
*/
private
$http_verify_url
=
'http://notify.alipay.com/trade/notify_query.do?'
;
private
$alipay_config
;
function
__construct
()
{
$this
->
alipay_config
=
\Yii
::
$app
->
params
[
'alipay'
];
}
/**
* 针对notify_url验证消息是否是支付宝发出的合法消息
* @return 验证结果
*/
function
verifyNotify
()
{
if
(
empty
(
$_POST
))
{
//判断POST来的数组是否为空
return
FALSE
;
}
else
{
//生成签名结果
$isSign
=
$this
->
getSignVeryfy
(
$_POST
,
$_POST
[
"sign"
]);
//获取支付宝远程服务器ATN结果(验证是否是支付宝发来的消息)
$responseTxt
=
'false'
;
if
(
!
empty
(
$_POST
[
"notify_id"
]))
{
$responseTxt
=
$this
->
getResponse
(
$_POST
[
"notify_id"
]);
}
//写日志记录
//if ($isSign) {
// $isSignStr = 'true';
//}
//else {
// $isSignStr = 'false';
//}
//$log_text = "responseTxt=".$responseTxt."\n notify_url_log:isSign=".$isSignStr.",";
//$log_text = $log_text.createLinkString($_POST);
//logResult($log_text);
//验证
//$responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关
//isSign的结果不是true,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关
if
(
preg_match
(
"/true$/i"
,
$responseTxt
)
&&
$isSign
)
{
return
TRUE
;
}
else
{
return
FALSE
;
}
}
}
/**
* 针对return_url验证消息是否是支付宝发出的合法消息
* @return 验证结果
*/
function
verifyReturn
()
{
if
(
empty
(
$_GET
))
{
//判断POST来的数组是否为空
return
FALSE
;
}
else
{
//生成签名结果
$isSign
=
$this
->
getSignVeryfy
(
$_GET
,
$_GET
[
"sign"
]);
//获取支付宝远程服务器ATN结果(验证是否是支付宝发来的消息)
$responseTxt
=
'false'
;
if
(
!
empty
(
$_GET
[
"notify_id"
]))
{
$responseTxt
=
$this
->
getResponse
(
$_GET
[
"notify_id"
]);
}
//写日志记录
//if ($isSign) {
// $isSignStr = 'true';
//}
//else {
// $isSignStr = 'false';
//}
//$log_text = "responseTxt=".$responseTxt."\n return_url_log:isSign=".$isSignStr.",";
//$log_text = $log_text.createLinkString($_GET);
//logResult($log_text);
//验证
//$responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关
//isSign的结果不是true,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关
if
(
preg_match
(
"/true$/i"
,
$responseTxt
)
&&
$isSign
)
{
return
TRUE
;
}
else
{
return
FALSE
;
}
}
}
/**
* 获取返回时的签名验证结果
* @param $para_temp 通知返回来的参数数组
* @param $sign 返回的签名结果
* @return 签名验证结果
*/
function
getSignVeryfy
(
$para_temp
,
$sign
)
{
//除去待签名参数数组中的空值和签名参数
$para_filter
=
paraFilter
(
$para_temp
);
//对待签名参数数组排序
$para_sort
=
argSort
(
$para_filter
);
//把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
$prestr
=
createLinkstring
(
$para_sort
);
$isSgin
=
FALSE
;
switch
(
strtoupper
(
trim
(
$this
->
alipay_config
[
'sign_type'
])))
{
case
"MD5"
:
$isSgin
=
md5Verify
(
$prestr
,
$sign
,
$this
->
alipay_config
[
'key'
]);
break
;
default
:
$isSgin
=
FALSE
;
}
return
$isSgin
;
}
/**
* 获取远程服务器ATN结果,验证返回URL
* @param $notify_id 通知校验ID
* @return 服务器ATN结果
* 验证结果集:
* invalid命令参数不对 出现这个错误,请检测返回处理中partner和key是否为空
* true 返回正确信息
* false 请检查防火墙或者是服务器阻止端口问题以及验证时间是否超过一分钟
*/
function
getResponse
(
$notify_id
)
{
$transport
=
strtolower
(
trim
(
$this
->
alipay_config
[
'transport'
]));
$partner
=
trim
(
$this
->
alipay_config
[
'partner'
]);
$veryfy_url
=
''
;
if
(
$transport
==
'https'
)
{
$veryfy_url
=
$this
->
https_verify_url
;
}
else
{
$veryfy_url
=
$this
->
http_verify_url
;
}
$veryfy_url
=
$veryfy_url
.
"partner="
.
$partner
.
"¬ify_id="
.
$notify_id
;
$responseTxt
=
getHttpResponseGET
(
$veryfy_url
,
$this
->
alipay_config
[
'cacert'
]);
return
$responseTxt
;
}
}
\ No newline at end of file
src/common/libs/alipay/libs/alipay_core.function.php
0 → 100755
View file @
6cced394
<?php
/* *
* 支付宝接口公用函数
* 详细:该类是请求、通知返回两个文件所调用的公用函数核心处理文件
* 版本:3.3
* 日期:2012-07-19
* 说明:
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
* 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。
*/
/**
* 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
* @param $para 需要拼接的数组
* return 拼接完成以后的字符串
*/
function
createLinkstring
(
$para
)
{
$arg
=
""
;
while
(
list
(
$key
,
$val
)
=
each
(
$para
))
{
$arg
.=
$key
.
"="
.
$val
.
"&"
;
}
//去掉最后一个&字符
$arg
=
substr
(
$arg
,
0
,
count
(
$arg
)
-
2
);
//如果存在转义字符,那么去掉转义
if
(
get_magic_quotes_gpc
()){
$arg
=
stripslashes
(
$arg
);}
return
$arg
;
}
/**
* 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对字符串做urlencode编码
* @param $para 需要拼接的数组
* return 拼接完成以后的字符串
*/
function
createLinkstringUrlencode
(
$para
)
{
$arg
=
""
;
while
(
list
(
$key
,
$val
)
=
each
(
$para
))
{
$arg
.=
$key
.
"="
.
urlencode
(
$val
)
.
"&"
;
}
//去掉最后一个&字符
$arg
=
substr
(
$arg
,
0
,
count
(
$arg
)
-
2
);
//如果存在转义字符,那么去掉转义
if
(
get_magic_quotes_gpc
()){
$arg
=
stripslashes
(
$arg
);}
return
$arg
;
}
/**
* 除去数组中的空值和签名参数
* @param $para 签名参数组
* return 去掉空值与签名参数后的新签名参数组
*/
function
paraFilter
(
$para
)
{
$para_filter
=
array
();
while
(
list
(
$key
,
$val
)
=
each
(
$para
))
{
if
(
$key
==
"sign"
||
$key
==
"sign_type"
||
$val
==
""
)
continue
;
else
$para_filter
[
$key
]
=
$para
[
$key
];
}
return
$para_filter
;
}
/**
* 对数组排序
* @param $para 排序前的数组
* return 排序后的数组
*/
function
argSort
(
$para
)
{
ksort
(
$para
);
reset
(
$para
);
return
$para
;
}
/**
* 写日志,方便测试(看网站需求,也可以改成把记录存入数据库)
* 注意:服务器需要开通fopen配置
* @param $word 要写入日志里的文本内容 默认值:空值
*/
function
logResult
(
$word
=
''
)
{
$fp
=
fopen
(
"log.txt"
,
"a"
);
flock
(
$fp
,
LOCK_EX
)
;
fwrite
(
$fp
,
"执行日期:"
.
strftime
(
"%Y%m%d%H%M%S"
,
time
())
.
"
\n
"
.
$word
.
"
\n
"
);
flock
(
$fp
,
LOCK_UN
);
fclose
(
$fp
);
}
/**
* 远程获取数据,POST模式
* 注意:
* 1.使用Crul需要修改服务器中php.ini文件的设置,找到php_curl.dll去掉前面的";"就行了
* 2.文件夹中cacert.pem是SSL证书请保证其路径有效,目前默认路径是:getcwd().'\\cacert.pem'
* @param $url 指定URL完整路径地址
* @param $cacert_url 指定当前工作目录绝对路径
* @param $para 请求的数据
* @param $input_charset 编码格式。默认值:空值
* return 远程输出的数据
*/
function
getHttpResponsePOST
(
$url
,
$cacert_url
,
$para
,
$input_charset
=
''
)
{
if
(
trim
(
$input_charset
)
!=
''
)
{
$url
=
$url
.
"_input_charset="
.
$input_charset
;
}
$curl
=
curl_init
(
$url
);
curl_setopt
(
$curl
,
CURLOPT_SSL_VERIFYPEER
,
true
);
//SSL证书认证
curl_setopt
(
$curl
,
CURLOPT_SSL_VERIFYHOST
,
2
);
//严格认证
curl_setopt
(
$curl
,
CURLOPT_CAINFO
,
$cacert_url
);
//证书地址
curl_setopt
(
$curl
,
CURLOPT_HEADER
,
0
);
// 过滤HTTP头
curl_setopt
(
$curl
,
CURLOPT_RETURNTRANSFER
,
1
);
// 显示输出结果
curl_setopt
(
$curl
,
CURLOPT_POST
,
true
);
// post传输数据
curl_setopt
(
$curl
,
CURLOPT_POSTFIELDS
,
$para
);
// post传输数据
$responseText
=
curl_exec
(
$curl
);
//var_dump( curl_error($curl) );//如果执行curl过程中出现异常,可打开此开关,以便查看异常内容
curl_close
(
$curl
);
return
$responseText
;
}
/**
* 远程获取数据,GET模式
* 注意:
* 1.使用Crul需要修改服务器中php.ini文件的设置,找到php_curl.dll去掉前面的";"就行了
* 2.文件夹中cacert.pem是SSL证书请保证其路径有效,目前默认路径是:getcwd().'\\cacert.pem'
* @param $url 指定URL完整路径地址
* @param $cacert_url 指定当前工作目录绝对路径
* return 远程输出的数据
*/
function
getHttpResponseGET
(
$url
,
$cacert_url
)
{
$curl
=
curl_init
(
$url
);
curl_setopt
(
$curl
,
CURLOPT_HEADER
,
0
);
// 过滤HTTP头
curl_setopt
(
$curl
,
CURLOPT_RETURNTRANSFER
,
1
);
// 显示输出结果
curl_setopt
(
$curl
,
CURLOPT_SSL_VERIFYPEER
,
true
);
//SSL证书认证
curl_setopt
(
$curl
,
CURLOPT_SSL_VERIFYHOST
,
2
);
//严格认证
curl_setopt
(
$curl
,
CURLOPT_CAINFO
,
$cacert_url
);
//证书地址
$responseText
=
curl_exec
(
$curl
);
//var_dump( curl_error($curl) );//如果执行curl过程中出现异常,可打开此开关,以便查看异常内容
curl_close
(
$curl
);
return
$responseText
;
}
/**
* 实现多种字符编码方式
* @param $input 需要编码的字符串
* @param $_output_charset 输出的编码格式
* @param $_input_charset 输入的编码格式
* return 编码后的字符串
*/
function
charsetEncode
(
$input
,
$_output_charset
,
$_input_charset
)
{
$output
=
""
;
if
(
!
isset
(
$_output_charset
)
)
$_output_charset
=
$_input_charset
;
if
(
$_input_charset
==
$_output_charset
||
$input
==
null
)
{
$output
=
$input
;
}
elseif
(
function_exists
(
"mb_convert_encoding"
))
{
$output
=
mb_convert_encoding
(
$input
,
$_output_charset
,
$_input_charset
);
}
elseif
(
function_exists
(
"iconv"
))
{
$output
=
iconv
(
$_input_charset
,
$_output_charset
,
$input
);
}
else
die
(
"sorry, you have no libs support for charset change."
);
return
$output
;
}
/**
* 实现多种字符解码方式
* @param $input 需要解码的字符串
* @param $_output_charset 输出的解码格式
* @param $_input_charset 输入的解码格式
* return 解码后的字符串
*/
function
charsetDecode
(
$input
,
$_input_charset
,
$_output_charset
)
{
$output
=
""
;
if
(
!
isset
(
$_input_charset
)
)
$_input_charset
=
$_input_charset
;
if
(
$_input_charset
==
$_output_charset
||
$input
==
null
)
{
$output
=
$input
;
}
elseif
(
function_exists
(
"mb_convert_encoding"
))
{
$output
=
mb_convert_encoding
(
$input
,
$_output_charset
,
$_input_charset
);
}
elseif
(
function_exists
(
"iconv"
))
{
$output
=
iconv
(
$_input_charset
,
$_output_charset
,
$input
);
}
else
die
(
"sorry, you have no libs support for charset changes."
);
return
$output
;
}
?>
\ No newline at end of file
src/common/libs/alipay/libs/alipay_md5.function.php
0 → 100755
View file @
6cced394
<?php
/* *
* MD5
* 详细:MD5加密
* 版本:3.3
* 日期:2012-07-19
* 说明:
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
* 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。
*/
/**
* 签名字符串
* @param $prestr 需要签名的字符串
* @param $key 私钥
* return 签名结果
*/
function
md5Sign
(
$prestr
,
$key
)
{
$prestr
=
$prestr
.
$key
;
return
md5
(
$prestr
);
}
/**
* 验证签名
* @param $prestr 需要签名的字符串
* @param $sign 签名结果
* @param $key 私钥
* return 签名结果
*/
function
md5Verify
(
$prestr
,
$sign
,
$key
)
{
$prestr
=
$prestr
.
$key
;
$mysgin
=
md5
(
$prestr
);
if
(
$mysgin
==
$sign
)
{
return
true
;
}
else
{
return
false
;
}
}
?>
\ No newline at end of file
src/common/libs/alipay/libs/alipay_notify.class.php
0 → 100755
View file @
6cced394
<?php
/* *
* 类名:AlipayNotify
* 功能:支付宝通知处理类
* 详细:处理支付宝各接口通知返回
* 版本:3.2
* 日期:2011-03-25
* 说明:
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
* 该代码仅供学习和研究支付宝接口使用,只是提供一个参考
*************************注意*************************
* 调试通知返回时,可查看或改写log日志的写入TXT里的数据,来检查通知返回是否正常
*/
require_once
(
"alipay_core.function.php"
);
require_once
(
"alipay_md5.function.php"
);
class
AlipayNotify
{
/**
* HTTPS形式消息验证地址
*/
var
$https_verify_url
=
'https://mapi.alipay.com/gateway.do?service=notify_verify&'
;
/**
* HTTP形式消息验证地址
*/
var
$http_verify_url
=
'http://notify.alipay.com/trade/notify_query.do?'
;
var
$alipay_config
;
function
__construct
(
$alipay_config
){
$this
->
alipay_config
=
$alipay_config
;
}
function
AlipayNotify
(
$alipay_config
)
{
$this
->
__construct
(
$alipay_config
);
}
/**
* 针对notify_url验证消息是否是支付宝发出的合法消息
* @return 验证结果
*/
function
verifyNotify
(){
if
(
empty
(
$_POST
))
{
//判断POST来的数组是否为空
return
false
;
}
else
{
//生成签名结果
$isSign
=
$this
->
getSignVeryfy
(
$_POST
,
$_POST
[
"sign"
]);
//获取支付宝远程服务器ATN结果(验证是否是支付宝发来的消息)
$responseTxt
=
'false'
;
if
(
!
empty
(
$_POST
[
"notify_id"
]))
{
$responseTxt
=
$this
->
getResponse
(
$_POST
[
"notify_id"
]);}
//写日志记录
//if ($isSign) {
// $isSignStr = 'true';
//}
//else {
// $isSignStr = 'false';
//}
//$log_text = "responseTxt=".$responseTxt."\n notify_url_log:isSign=".$isSignStr.",";
//$log_text = $log_text.createLinkString($_POST);
//logResult($log_text);
//验证
//$responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关
//isSign的结果不是true,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关
if
(
preg_match
(
"/true$/i"
,
$responseTxt
)
&&
$isSign
)
{
return
true
;
}
else
{
return
false
;
}
}
}
/**
* 针对return_url验证消息是否是支付宝发出的合法消息
* @return 验证结果
*/
function
verifyReturn
(){
if
(
empty
(
$_GET
))
{
//判断POST来的数组是否为空
return
false
;
}
else
{
//生成签名结果
$isSign
=
$this
->
getSignVeryfy
(
$_GET
,
$_GET
[
"sign"
]);
//获取支付宝远程服务器ATN结果(验证是否是支付宝发来的消息)
$responseTxt
=
'false'
;
if
(
!
empty
(
$_GET
[
"notify_id"
]))
{
$responseTxt
=
$this
->
getResponse
(
$_GET
[
"notify_id"
]);}
//写日志记录
//if ($isSign) {
// $isSignStr = 'true';
//}
//else {
// $isSignStr = 'false';
//}
//$log_text = "responseTxt=".$responseTxt."\n return_url_log:isSign=".$isSignStr.",";
//$log_text = $log_text.createLinkString($_GET);
//logResult($log_text);
//验证
//$responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关
//isSign的结果不是true,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关
if
(
preg_match
(
"/true$/i"
,
$responseTxt
)
&&
$isSign
)
{
return
true
;
}
else
{
return
false
;
}
}
}
/**
* 获取返回时的签名验证结果
* @param $para_temp 通知返回来的参数数组
* @param $sign 返回的签名结果
* @return 签名验证结果
*/
function
getSignVeryfy
(
$para_temp
,
$sign
)
{
//除去待签名参数数组中的空值和签名参数
$para_filter
=
paraFilter
(
$para_temp
);
//对待签名参数数组排序
$para_sort
=
argSort
(
$para_filter
);
//把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
$prestr
=
createLinkstring
(
$para_sort
);
$isSgin
=
false
;
switch
(
strtoupper
(
trim
(
$this
->
alipay_config
[
'sign_type'
])))
{
case
"MD5"
:
$isSgin
=
md5Verify
(
$prestr
,
$sign
,
$this
->
alipay_config
[
'key'
]);
break
;
default
:
$isSgin
=
false
;
}
return
$isSgin
;
}
/**
* 获取远程服务器ATN结果,验证返回URL
* @param $notify_id 通知校验ID
* @return 服务器ATN结果
* 验证结果集:
* invalid命令参数不对 出现这个错误,请检测返回处理中partner和key是否为空
* true 返回正确信息
* false 请检查防火墙或者是服务器阻止端口问题以及验证时间是否超过一分钟
*/
function
getResponse
(
$notify_id
)
{
$transport
=
strtolower
(
trim
(
$this
->
alipay_config
[
'transport'
]));
$partner
=
trim
(
$this
->
alipay_config
[
'partner'
]);
$veryfy_url
=
''
;
if
(
$transport
==
'https'
)
{
$veryfy_url
=
$this
->
https_verify_url
;
}
else
{
$veryfy_url
=
$this
->
http_verify_url
;
}
$veryfy_url
=
$veryfy_url
.
"partner="
.
$partner
.
"¬ify_id="
.
$notify_id
;
$responseTxt
=
getHttpResponseGET
(
$veryfy_url
,
$this
->
alipay_config
[
'cacert'
]);
return
$responseTxt
;
}
}
?>
src/common/libs/alipay/libs/alipay_submit.class.php
0 → 100755
View file @
6cced394
<?php
/* *
* 类名:AlipaySubmit
* 功能:支付宝各接口请求提交类
* 详细:构造支付宝各接口表单HTML文本,获取远程HTTP数据
* 版本:3.3
* 日期:2012-07-23
* 说明:
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
* 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。
*/
require_once
(
"alipay_core.function.php"
);
require_once
(
"alipay_md5.function.php"
);
class
AlipaySubmit
{
var
$alipay_config
;
/**
*支付宝网关地址(新)
*/
var
$alipay_gateway_new
=
'https://mapi.alipay.com/gateway.do?'
;
function
__construct
(
$alipay_config
){
$this
->
alipay_config
=
$alipay_config
;
}
function
AlipaySubmit
(
$alipay_config
)
{
$this
->
__construct
(
$alipay_config
);
}
/**
* 生成签名结果
* @param $para_sort 已排序要签名的数组
* return 签名结果字符串
*/
function
buildRequestMysign
(
$para_sort
)
{
//把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
$prestr
=
createLinkstring
(
$para_sort
);
$mysign
=
""
;
switch
(
strtoupper
(
trim
(
$this
->
alipay_config
[
'sign_type'
])))
{
case
"MD5"
:
$mysign
=
md5Sign
(
$prestr
,
$this
->
alipay_config
[
'key'
]);
break
;
default
:
$mysign
=
""
;
}
return
$mysign
;
}
/**
* 生成要请求给支付宝的参数数组
* @param $para_temp 请求前的参数数组
* @return 要请求的参数数组
*/
function
buildRequestPara
(
$para_temp
)
{
//除去待签名参数数组中的空值和签名参数
$para_filter
=
paraFilter
(
$para_temp
);
//对待签名参数数组排序
$para_sort
=
argSort
(
$para_filter
);
//生成签名结果
$mysign
=
$this
->
buildRequestMysign
(
$para_sort
);
//签名结果与签名方式加入请求提交参数组中
$para_sort
[
'sign'
]
=
$mysign
;
$para_sort
[
'sign_type'
]
=
strtoupper
(
trim
(
$this
->
alipay_config
[
'sign_type'
]));
return
$para_sort
;
}
/**
* 生成要请求给支付宝的参数数组
* @param $para_temp 请求前的参数数组
* @return 要请求的参数数组字符串
*/
function
buildRequestParaToString
(
$para_temp
)
{
//待请求参数数组
$para
=
$this
->
buildRequestPara
(
$para_temp
);
//把参数组中所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对字符串做urlencode编码
$request_data
=
createLinkstringUrlencode
(
$para
);
return
$request_data
;
}
/**
* 建立请求,以表单HTML形式构造(默认)
* @param $para_temp 请求参数数组
* @param $method 提交方式。两个值可选:post、get
* @param $button_name 确认按钮显示文字
* @return 提交表单HTML文本
*/
function
buildRequestForm
(
$para_temp
,
$method
,
$button_name
)
{
//待请求参数数组
$para
=
$this
->
buildRequestPara
(
$para_temp
);
$sHtml
=
"<form id='alipaysubmit' name='alipaysubmit' action='"
.
$this
->
alipay_gateway_new
.
"_input_charset="
.
trim
(
strtolower
(
$this
->
alipay_config
[
'input_charset'
]))
.
"' method='"
.
$method
.
"'>"
;
while
(
list
(
$key
,
$val
)
=
each
(
$para
))
{
$sHtml
.=
"<input type='hidden' name='"
.
$key
.
"' value='"
.
$val
.
"'/>"
;
}
//submit按钮控件请不要含有name属性
$sHtml
=
$sHtml
.
"<input type='submit' value='"
.
$button_name
.
"' style='display:none;'></form>"
;
$sHtml
=
$sHtml
.
"<script>document.forms['alipaysubmit'].submit();</script>"
;
return
$sHtml
;
}
/**
* 用于防钓鱼,调用接口query_timestamp来获取时间戳的处理函数
* 注意:该功能PHP5环境及以上支持,因此必须服务器、本地电脑中装有支持DOMDocument、SSL的PHP配置环境。建议本地调试时使用PHP开发软件
* return 时间戳字符串
*/
function
query_timestamp
()
{
$url
=
$this
->
alipay_gateway_new
.
"service=query_timestamp&partner="
.
trim
(
strtolower
(
$this
->
alipay_config
[
'partner'
]))
.
"&_input_charset="
.
trim
(
strtolower
(
$this
->
alipay_config
[
'input_charset'
]));
$encrypt_key
=
""
;
$doc
=
new
DOMDocument
();
$doc
->
load
(
$url
);
$itemEncrypt_key
=
$doc
->
getElementsByTagName
(
"encrypt_key"
);
$encrypt_key
=
$itemEncrypt_key
->
item
(
0
)
->
nodeValue
;
return
$encrypt_key
;
}
}
?>
\ No newline at end of file
src/common/models/Course.php
View file @
6cced394
...
@@ -96,4 +96,27 @@ class Course extends \yii\db\ActiveRecord
...
@@ -96,4 +96,27 @@ class Course extends \yii\db\ActiveRecord
$result
=
self
::
find
()
->
select
(
'id'
)
->
where
(
'id=:id'
,
[
':id'
=>
$id
])
->
one
();
$result
=
self
::
find
()
->
select
(
'id'
)
->
where
(
'id=:id'
,
[
':id'
=>
$id
])
->
one
();
return
$result
===
NULL
?
FALSE
:
TRUE
;
return
$result
===
NULL
?
FALSE
:
TRUE
;
}
}
/**
* 根据课程id获取课程信息
* @param $courseId
* @return array|null|\yii\db\ActiveRecord
*/
public
static
function
findByCourseId
(
$courseId
)
{
$tableA
=
self
::
tableName
();
$tableB
=
Courseware
::
tableName
();
return
self
::
find
()
->
select
(
"
$tableA
.id,
$tableA
.classed_id,
$tableA
.avatar,
$tableA
.name,
$tableA
.price,
$tableA
.free_time,
$tableA
.intro,
$tableA
.preview_pic,
$tableA
.status,
$tableA
.created_at,
$tableB
.name,
$tableB
.size,
$tableB
.format"
)
->
where
(
"
$tableA
.id=:id"
,
[
'id'
=>
$courseId
])
->
join
(
'left join'
,
$tableB
,
"
$tableA
.id=
$tableB
.course_id"
)
->
asArray
()
->
one
();
}
/**
* 获取课程的基本信息
* @param $courseId
* @return array|null|\yii\db\ActiveRecord
*/
public
static
function
findBaseInfoByCourseId
(
$courseId
)
{
return
self
::
find
()
->
select
(
"user_id,price,name"
)
->
where
(
"id=:id"
,
[
'id'
=>
$courseId
])
->
asArray
()
->
one
();
}
}
}
src/common/models/Orders.php
View file @
6cced394
...
@@ -21,6 +21,11 @@ use yii\redis\ActiveRecord;
...
@@ -21,6 +21,11 @@ use yii\redis\ActiveRecord;
*/
*/
class
Orders
extends
\yii\db\ActiveRecord
class
Orders
extends
\yii\db\ActiveRecord
{
{
//订单支付状体
const
UNPAID
=
0
;
const
PAID
=
1
;
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
...
@@ -82,7 +87,7 @@ class Orders extends \yii\db\ActiveRecord
...
@@ -82,7 +87,7 @@ class Orders extends \yii\db\ActiveRecord
* @param $userId
* @param $userId
* @return array|\yii\db\ActiveRecord[]
* @return array|\yii\db\ActiveRecord[]
*/
*/
public
static
function
get
PurchasedCourseByUserId
(
$userId
)
public
static
function
find
PurchasedCourseByUserId
(
$userId
)
{
{
$tableA
=
self
::
tableName
();
$tableA
=
self
::
tableName
();
$tableB
=
Course
::
tableName
();
$tableB
=
Course
::
tableName
();
...
@@ -93,4 +98,19 @@ class Orders extends \yii\db\ActiveRecord
...
@@ -93,4 +98,19 @@ class Orders extends \yii\db\ActiveRecord
}
}
/**
* 判断是否存在订单号
* @param $userId
* @param $courseId
* @return array
*/
public
static
function
findByUserIdAndCourseId
(
$userId
,
$courseId
)
{
return
self
::
find
()
->
select
(
'*'
)
->
where
(
'user_id=:user_id and course_id=:course_id'
,
[
':user_id'
=>
$userId
,
':course_id'
=>
$courseId
])
->
one
();
}
}
}
src/composer.json
View file @
6cced394
...
@@ -15,7 +15,9 @@
...
@@ -15,7 +15,9 @@
"yiisoft/yii2-swiftmailer"
:
"*"
,
"yiisoft/yii2-swiftmailer"
:
"*"
,
"yiisoft/yii2-redis"
:
"^2.0"
,
"yiisoft/yii2-redis"
:
"^2.0"
,
"guzzlehttp/guzzle"
:
"^6.2"
,
"guzzlehttp/guzzle"
:
"^6.2"
,
"qiniu/php-sdk"
:
"^7.0"
"qiniu/php-sdk"
:
"^7.0"
,
"light/yii2-xmlparser"
:
"*"
,
"2amigos/yii2-qrcode-helper"
:
"*"
},
},
"require-dev"
:
{
"require-dev"
:
{
"yiisoft/yii2-codeception"
:
"*"
,
"yiisoft/yii2-codeception"
:
"*"
,
...
...
src/composer.lock
View file @
6cced394
...
@@ -4,9 +4,65 @@
...
@@ -4,9 +4,65 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
"This file is @generated automatically"
],
],
"hash": "5
8c51098f2b70fd0b7cacfcb4527cb2f
",
"hash": "5
53e6afb2f94832a2b21ea5d6301d656
",
"content-hash": "
ed7bd775092a2dda1558bb321d31c8c4
",
"content-hash": "
b2a9e1b6aa19ba113948022d2525b40b
",
"packages": [
"packages": [
{
"name": "2amigos/yii2-qrcode-helper",
"version": "1.0.2",
"source": {
"type": "git",
"url": "https://github.com/2amigos/yii2-qrcode-helper.git",
"reference": "827a79d0e498026119c8cdcf724d81be2e0daa5f"
},
"dist": {
"type": "zip",
"url": "https://packagist.phpcomposer.com/files/2amigos/yii2-qrcode-helper/827a79d0e498026119c8cdcf724d81be2e0daa5f.zip",
"reference": "827a79d0e498026119c8cdcf724d81be2e0daa5f",
"shasum": ""
},
"require": {
"yiisoft/yii2": "*"
},
"require-dev": {
"phpunit/phpunit": "4.*",
"scrutinizer/ocular": "~1.1"
},
"type": "yii2-extension",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"psr-4": {
"dosamigos\\qrcode\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "2amigOS! Consulting Group",
"email": "hola@2amigos.us",
"homepage": "http://2amigos.us",
"role": "Developer"
}
],
"description": "Create QrCodes based on libqrencode C library.",
"keywords": [
"2amigos",
"extension",
"helper",
"qrcode",
"yii",
"yii 2",
"yii2"
],
"time": "2015-03-16 21:26:14"
},
{
{
"name": "bower-asset/bootstrap",
"name": "bower-asset/bootstrap",
"version": "v3.3.7",
"version": "v3.3.7",
...
@@ -470,6 +526,52 @@
...
@@ -470,6 +526,52 @@
],
],
"time": "2016-06-24 23:00:38"
"time": "2016-06-24 23:00:38"
},
},
{
"name": "light/yii2-xmlparser",
"version": "0.2.11",
"source": {
"type": "git",
"url": "https://github.com/lichunqiang/yii2-xmlparser.git",
"reference": "0e86c5d214dd04e28e4360de22aa1e2c7484e318"
},
"dist": {
"type": "zip",
"url": "https://packagist.phpcomposer.com/files/lichunqiang/yii2-xmlparser/0e86c5d214dd04e28e4360de22aa1e2c7484e318.zip",
"reference": "0e86c5d214dd04e28e4360de22aa1e2c7484e318",
"shasum": ""
},
"require": {
"php": ">=5.4.0",
"yiisoft/yii2": "2.0.*"
},
"require-dev": {
"phpunit/phpunit": "4.4.*"
},
"type": "library",
"autoload": {
"psr-4": {
"light\\yii2\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "lichunqiang",
"email": "light-li@hotmail.com"
}
],
"description": "yii2 xml request parser",
"keywords": [
"parse",
"request",
"xml",
"yii2"
],
"time": "2015-08-15 16:07:34"
},
{
{
"name": "psr/http-message",
"name": "psr/http-message",
"version": "1.0.1",
"version": "1.0.1",
...
...
src/frontend/controllers/HomeController.php
View file @
6cced394
...
@@ -2,13 +2,19 @@
...
@@ -2,13 +2,19 @@
namespace
frontend\controllers
;
namespace
frontend\controllers
;
use
common\libs\alipay\AliPay
;
use
common\libs\WeixinPay
;
use
common\models\Comments
;
use
common\models\Comments
;
use
common\models\Course
;
use
common\models\Course
;
use
common\models\Courseware
;
use
common\models\Courseware
;
use
common\models\Favorite
;
use
common\models\Favorite
;
use
common\models\Orders
;
use
common\models\Support
;
use
common\models\Support
;
use
dosamigos\qrcode\QrCode
;
use
GuzzleHttp\Client
;
use
Yii
;
use
Yii
;
use
common\libs\Utils
;
use
common\libs\Utils
;
use
yii\base\ErrorException
;
use
yii\base\InvalidParamException
;
use
yii\base\InvalidParamException
;
use
yii\filters\AccessControl
;
use
yii\filters\AccessControl
;
use
yii\helpers\Html
;
use
yii\helpers\Html
;
...
@@ -22,15 +28,15 @@ class HomeController extends \yii\web\Controller
...
@@ -22,15 +28,15 @@ class HomeController extends \yii\web\Controller
*/
*/
public
function
behaviors
()
public
function
behaviors
()
{
{
return
[
$rules
=
[
//权限限制
//权限限制
'access'
=>
[
'access'
=>
[
'class'
=>
AccessControl
::
className
(),
'class'
=>
AccessControl
::
className
(),
'only'
=>
[
'support'
,
'favorite'
,
'comments'
],
'only'
=>
[
'support'
,
'favorite'
,
'comments'
,
'pay'
],
'rules'
=>
[
'rules'
=>
[
[
[
'allow'
=>
TRUE
,
'allow'
=>
TRUE
,
'actions'
=>
[
'support'
,
'favorite'
],
'actions'
=>
[
'support'
,
'favorite'
,
'pay'
],
'roles'
=>
[
'@'
],
'roles'
=>
[
'@'
],
],
],
[
[
...
@@ -43,10 +49,20 @@ class HomeController extends \yii\web\Controller
...
@@ -43,10 +49,20 @@ class HomeController extends \yii\web\Controller
]
]
];
];
return
$rules
;
}
}
public
function
actionIndex
()
/**
* 首页
* @param $courseId 课程id
* @return string
*/
public
function
actionIndex
(
$courseId
)
{
{
$result
=
Course
::
findByCourseId
(
$courseId
);
var_dump
(
$result
);
return
$this
->
render
(
'index'
);
return
$this
->
render
(
'index'
);
}
}
...
@@ -153,4 +169,124 @@ class HomeController extends \yii\web\Controller
...
@@ -153,4 +169,124 @@ class HomeController extends \yii\web\Controller
throw
new
\yii\web\ForbiddenHttpException
(
'非法请求'
);
throw
new
\yii\web\ForbiddenHttpException
(
'非法请求'
);
}
}
}
}
/**
* 支付宝支付请求
* @throws InvalidParamException
*/
public
function
actionPay
(
$courseId
)
{
$courseBaseInfo
=
Course
::
findBaseInfoByCourseId
(
$courseId
);
if
(
$courseBaseInfo
!==
NULL
)
{
$userId
=
Yii
::
$app
->
user
->
identity
->
getId
();
$order
=
Orders
::
findByUserIdAndCourseId
(
$userId
,
$courseId
);
$price
=
$courseBaseInfo
[
'price'
];
$number
=
$this
->
generateOrderNumber
(
$userId
,
$courseId
,
$price
);
//判断订单是否存在
if
(
$order
===
NULL
)
{
$order
=
new
Orders
();
$order
->
user_id
=
$userId
;
$order
->
course_id
=
$courseId
;
$order
->
number
=
$number
;
$order
->
credit
=
$price
;
$order
->
status
=
Orders
::
UNPAID
;
$order
->
pay_order
=
'0'
;
$order
->
save
();
}
else
{
//价格变动后给支付宝的订单编号也会变动
if
(
$price
!==
$order
->
credit
)
{
$order
->
credit
=
$price
;
$order
->
number
=
$number
;
$order
->
update
();
}
}
$alipay
=
new
AliPay
();
$parameter
=
array
(
"out_trade_no"
=>
$number
,
//订单号
"subject"
=>
"购买课程-
{
$courseBaseInfo
[
'name'
]
}
"
,
//订单名称
"total_fee"
=>
$price
,
//付款金额
"body"
=>
'云崖购买'
,
//商品描述
);
$html_text
=
$alipay
->
buildRequestForm
(
$parameter
,
"get"
,
"确认"
);
echo
$html_text
;
}
else
{
throw
new
InvalidParamException
(
'参数错误'
);
}
}
/**
* 获取微信支付的二维码
*/
public
function
actionWeixinPayQrcode
()
{
// $userId = Yii::$app->user->identity->getId();
// $courseBaseInfo = Course::findBaseInfoByCourseId($courseId);
// if ($courseBaseInfo !== NULL) {
// $price = $courseBaseInfo['price'];
// $productId = $this->generateOrderNumber($userId, $courseId, $price);
// $weixinPay = WeixinPay::getInstance();
// return QrCode::jpg($weixinPay->makePayUrl($productId));
// } else {
// throw new InvalidParamException('参数错误');
// }
//
$weixinPay
=
WeixinPay
::
getInstance
();
$url
=
$weixinPay
->
makePayUrl
(
time
());
// var_dump($url);exit;
return
QrCode
::
jpg
((
$url
));
}
public
function
actionMobilePay
(){
$weixinpay
=
\Yii
::
$app
->
params
[
'weixinpay'
];
$client
=
new
Client
(
[
'timeout'
=>
8
,
'verify'
=>
FALSE
,
'connect_timeout'
=>
8
]
);
$order_id
=
'12312312323'
;
$uri
=
WeixinPay
::
UNIFIEDORDER
;
$xml
=
[
'appid'
=>
$weixinpay
[
'appid'
],
'mch_id'
=>
$weixinpay
[
'mchid'
],
'device_info'
=>
"WEB"
,
'nonce_str'
=>
Yii
::
$app
->
security
->
generateRandomString
(
16
),
'sign'
=>
''
,
'body'
=>
'最课堂-课程购买'
,
'out_trade_no'
=>
$order_id
,
'total_fee'
=>
1
,
'spbill_create_ip'
=>
$_SERVER
[
'SERVER_ADDR'
],
'notify_url'
=>
WeixinPay
::
NOTIFY_URL
,
'trade_type'
=>
'MWEB'
,
];
$xml
[
'sign'
]
=
WeixinPay
::
makeWeixinPaySign
(
$xml
,
$weixinpay
[
'key'
]);
$xml
=
Utils
::
assocArrayToXML
(
'xml'
,
$xml
);
$reponse
=
$client
->
request
(
'POST'
,
$uri
,
[
'Content-Type'
=>
'text/xml; charset=UTF8'
,
'body'
=>
$xml
]);
$reponse
=
$reponse
->
getBody
();
$result
=
((
string
)
$reponse
);
$result
=
Utils
::
xmlToArray
(
$result
);
var_dump
(
$result
);
}
/**
* 生成订单号
* 格式 时间_uid_courseId
* @param $userId
* @param $courseId
* @param $price
* @return false|string
*/
private
function
generateOrderNumber
(
$userId
,
$courseId
,
$price
)
{
return
md5
(
date
(
"YmdHis"
,
time
())
.
"_
{
$userId
}
_
{
$courseId
}
_
{
$price
}
"
);
}
}
}
src/frontend/controllers/PayController.php
0 → 100644
View file @
6cced394
<?php
/**
* Created by PhpStorm.
* User: xiabin
* Date: 2016/10/12
* Time: 下午4:05
*/
namespace
frontend\controllers
;
use
common\libs\alipay\AlipayNotify
;
use
common\libs\Utils
;
use
common\libs\WeixinPay
;
use
common\models\Consume
;
use
common\models\Course
;
use
common\models\Income
;
use
common\models\Orders
;
use
dosamigos\qrcode\formats\Wifi
;
use
GuzzleHttp\Client
;
use
yii\log\Logger
;
use
yii\web\Controller
;
class
PayController
extends
Controller
{
public
$enableCsrfValidation
=
FALSE
;
public
function
actionAlipayNotify
()
{
//计算得出通知验证结果
$alipayNotify
=
new
AlipayNotify
();
$verify_result
=
$alipayNotify
->
verifyNotify
();
if
(
$verify_result
)
{
//验证成功
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//请在这里加上商户的业务逻辑程序代
//——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
//获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表
//商户订单号
$out_trade_no
=
$_POST
[
'out_trade_no'
];
$trade_no
=
$_POST
[
'trade_no'
];
$order
=
Orders
::
findOne
([
'number'
=>
$out_trade_no
]);
//交易状态
$trade_status
=
$_POST
[
'trade_status'
];
//并添加消费记录
$consume
=
new
Consume
();
$consume
->
orders_id
=
$order
->
id
;
$consume
->
user_id
=
$order
->
user_id
;
$consume
->
save
();
//添加收入记录
$income
=
new
Income
();
$income
->
orders_id
=
$order
->
id
;
$courseInfo
=
Course
::
findBaseInfoByCourseId
(
$order
->
course_id
);
$income
->
user_id
=
$courseInfo
[
'user_id'
];
$income
->
save
();
if
(
$trade_status
==
'TRADE_FINISHED'
or
$trade_status
==
'TRADE_SUCCESS'
)
{
$order
->
pay_order
=
$trade_no
;
$order
->
status
=
Orders
::
PAID
;
$order
->
update
();
}
//——请根据您的业务逻辑来编写程序(以上代码仅作参考)——
echo
"success"
;
//请不要修改或删除
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
else
{
//验证失败
echo
"fail"
;
//调试用,写文本函数记录程序运行情况是否正常
//logResult("这里写入想要调试的代码变量值,或其他运行的结果记录");
}
}
/**
* weixin支付回调接口
* @return object
*/
public
function
actionWeixinPayCallback
()
{
//获取
$data
=
(
\Yii
::
$app
->
request
->
post
());
$weixinpay
=
\Yii
::
$app
->
params
[
'weixinpay'
];
$order_id
=
$data
[
'product_id'
];
//发送统一下单请求
$client
=
new
Client
(
[
'timeout'
=>
8
,
'verify'
=>
FALSE
,
'connect_timeout'
=>
8
]
);
$uri
=
WeixinPay
::
UNIFIEDORDER
;
$xml
=
[
'appid'
=>
$weixinpay
[
'appid'
],
'mch_id'
=>
$weixinpay
[
'mchid'
],
'device_info'
=>
"WEB"
,
'nonce_str'
=>
$data
[
'nonce_str'
],
'sign'
=>
''
,
'body'
=>
'最课堂-课程购买'
,
'out_trade_no'
=>
$order_id
,
'total_fee'
=>
1
,
'spbill_create_ip'
=>
$_SERVER
[
'SERVER_ADDR'
],
'notify_url'
=>
WeixinPay
::
NOTIFY_URL
,
'trade_type'
=>
'NATIVE'
,
];
$xml
[
'sign'
]
=
WeixinPay
::
makeWeixinPaySign
(
$xml
,
$weixinpay
[
'key'
]);
$xml
=
Utils
::
assocArrayToXML
(
'xml'
,
$xml
);
$reponse
=
$client
->
request
(
'POST'
,
$uri
,
[
'Content-Type'
=>
'text/xml; charset=UTF8'
,
'body'
=>
$xml
]);
$reponse
=
$reponse
->
getBody
();
$result
=
((
string
)
$reponse
);
$result
=
Utils
::
xmlToArray
(
$result
);
$flag
=
TRUE
;
if
(
$result
[
'return_code'
]
!==
'SUCCESS'
)
{
$flag
=
FALSE
;
\Yii
::
getLogger
()
->
log
(
$result
[
'return_msg'
],
Logger
::
LEVEL_ERROR
);
}
else
if
(
$result
[
'result_code'
]
!==
'SUCCESS'
)
{
$flag
=
FALSE
;
\Yii
::
getLogger
()
->
log
(
$result
[
'err_code'
]
.
':'
.
$result
[
'err_code_des'
],
Logger
::
LEVEL_ERROR
);
}
if
(
$flag
===
FALSE
)
{
return
\Yii
::
createObject
([
'class'
=>
'yii\web\Response'
,
'format'
=>
\yii\web\Response
::
FORMAT_XML
,
'formatters'
=>
[
\yii\web\Response
::
FORMAT_XML
=>
[
'class'
=>
'yii\web\XmlResponseFormatter'
,
'rootTag'
=>
'xml'
,
//根节点
],
],
'data'
=>
$result
]);
}
if
(
$result
[
'sign'
]
!==
WeixinPay
::
makeWeixinPaySign
(
$result
,
$weixinpay
[
'key'
]))
{
return
\Yii
::
createObject
([
'class'
=>
'yii\web\Response'
,
'format'
=>
\yii\web\Response
::
FORMAT_XML
,
'formatters'
=>
[
\yii\web\Response
::
FORMAT_XML
=>
[
'class'
=>
'yii\web\XmlResponseFormatter'
,
'rootTag'
=>
'xml'
,
//根节点
],
],
'data'
=>
[
'return_code'
=>
'FAIL'
,
'return_msg'
=>
'数据错误'
]
]);
}
$prepay_id
=
$result
[
'prepay_id'
];
$return
=
[
'return_code'
=>
'SUCCESS'
,
'appid'
=>
$weixinpay
[
'appid'
],
'mch_id'
=>
$weixinpay
[
'mchid'
],
'nonce_str'
=>
$result
[
'nonce_str'
],
'prepay_id'
=>
$prepay_id
,
'result_code'
=>
'SUCCESS'
,
'sign'
=>
''
];
$return
[
'sign'
]
=
WeixinPay
::
makeWeixinPaySign
(
$return
,
$weixinpay
[
'key'
]);
//生成订单数据
return
\Yii
::
createObject
([
'class'
=>
'yii\web\Response'
,
'format'
=>
\yii\web\Response
::
FORMAT_XML
,
'formatters'
=>
[
\yii\web\Response
::
FORMAT_XML
=>
[
'class'
=>
'yii\web\XmlResponseFormatter'
,
'rootTag'
=>
'xml'
,
//根节点
],
],
'data'
=>
$return
]);
}
/**
* 微信notify_url
*/
public
function
actionWeixinNotify
()
{
$data
=
(
\Yii
::
$app
->
request
->
post
());
$flag
=
TRUE
;
if
(
$data
[
'return_code'
]
!==
'SUCCESS'
)
{
$flag
=
FALSE
;
\Yii
::
getLogger
()
->
log
(
$data
[
'return_msg'
],
Logger
::
LEVEL_ERROR
);
}
elseif
(
$data
[
'result_code'
]
!==
'SUCCESS'
)
{
$flag
=
FALSE
;
\Yii
::
getLogger
()
->
log
(
$data
[
'err_code'
]
.
':'
.
$data
[
'err_code_des'
],
Logger
::
LEVEL_ERROR
);
}
if
(
$flag
===
FALSE
)
{
return
\Yii
::
createObject
([
'class'
=>
'yii\web\Response'
,
'format'
=>
\yii\web\Response
::
FORMAT_XML
,
'formatters'
=>
[
\yii\web\Response
::
FORMAT_XML
=>
[
'class'
=>
'yii\web\XmlResponseFormatter'
,
'rootTag'
=>
'xml'
,
//根节点
],
],
'data'
=>
$data
]);
}
$weixinpay
=
\Yii
::
$app
->
params
[
'weixinpay'
];
if
(
$data
[
'sign'
]
!==
$weixinpay
[
'key'
])
{
return
\Yii
::
createObject
([
'class'
=>
'yii\web\Response'
,
'format'
=>
\yii\web\Response
::
FORMAT_XML
,
'formatters'
=>
[
\yii\web\Response
::
FORMAT_XML
=>
[
'class'
=>
'yii\web\XmlResponseFormatter'
,
'rootTag'
=>
'xml'
,
//根节点
],
],
'data'
=>
[
'return_code'
=>
'FAIL'
,
'return_msg'
=>
'数据错误'
]
]);
}
$orderId
=
$data
[
'out_trade_no'
];
$payOrder
=
$data
[
'transaction_id'
];
//修改订单状态
$order
=
Orders
::
findOne
([
'number'
=>
$orderId
]);
$order
->
status
=
Orders
::
PAID
;
$order
->
pay_order
=
$payOrder
;
$order
->
update
();
//并添加消费记录
$consume
=
new
Consume
();
$consume
->
orders_id
=
$order
->
id
;
$consume
->
user_id
=
$order
->
user_id
;
$consume
->
save
();
//添加收入记录
$income
=
new
Income
();
$income
->
orders_id
=
$order
->
id
;
$courseInfo
=
Course
::
findBaseInfoByCourseId
(
$order
->
course_id
);
$income
->
user_id
=
$courseInfo
[
'user_id'
];
$income
->
save
();
return
\Yii
::
createObject
([
'class'
=>
'yii\web\Response'
,
'format'
=>
\yii\web\Response
::
FORMAT_XML
,
'formatters'
=>
[
\yii\web\Response
::
FORMAT_XML
=>
[
'class'
=>
'yii\web\XmlResponseFormatter'
,
'rootTag'
=>
'xml'
,
//根节点
],
],
'data'
=>
[
'return_code'
=>
'SUCCESS'
,
'return_msg'
=>
'OK'
]
]);
}
}
opcache_invalidate
(
__FILE__
);
\ No newline at end of file
src/frontend/controllers/TestController.php
0 → 100644
View file @
6cced394
<?php
/**
* Created by PhpStorm.
* User: xiabin
* Date: 2016/10/13
* Time: 上午9:57
*/
namespace
frontend\controllers
;
use
common\libs\Utils
;
use
GuzzleHttp\Client
;
use
GuzzleHttp\Psr7\Request
;
use
yii\log\Logger
;
use
yii\web\Controller
;
class
TestController
extends
Controller
{
public
$enableCsrfValidation
=
FALSE
;
public
function
actionIndex2
()
{
$data
=
(
\Yii
::
$app
->
request
->
post
());
$order_id
=
date
(
"YmdHis"
);
$order_id
=
'20161013135950'
;
//发送统一下单请求
$client
=
new
Client
(
[
'timeout'
=>
8
,
'verify'
=>
FALSE
,
'connect_timeout'
=>
8
]
);
$uri
=
'https://api.mch.weixin.qq.com/pay/unifiedorder'
;
$weixinpay
=
\Yii
::
$app
->
params
[
'weixinpay'
];
$xml
=
[
'appid'
=>
$weixinpay
[
'appid'
],
'mch_id'
=>
$weixinpay
[
'mchid'
],
'device_info'
=>
"WEB"
,
'nonce_str'
=>
\Yii
::
$app
->
security
->
generateRandomString
(
16
),
'sign'
=>
''
,
'body'
=>
'云崖充值中心-课程购买'
,
'out_trade_no'
=>
$order_id
,
'total_fee'
=>
1
,
'spbill_create_ip'
=>
'114.112.65.4'
,
'notify_url'
=>
'http://c.pp.cc/frontend/web/index.php/pay/weixin-notify'
,
'trade_type'
=>
'NATIVE'
,
];
$xml
[
'sign'
]
=
Utils
::
makeWeixinPaySign
(
$xml
,
$weixinpay
[
'key'
]);
$xml
=
Utils
::
assocArrayToXML
(
'xml'
,
$xml
);
$reponse
=
$client
->
request
(
'POST'
,
$uri
,
[
'Content-Type'
=>
'text/xml; charset=UTF8'
,
'body'
=>
$xml
]);
$reponse
=
$reponse
->
getBody
();
$result
=
((
string
)
$reponse
);
$result
=
simplexml_load_string
(
$result
);
$prepay_id
=
(
string
)
$result
->
prepay_id
;
$return
=
[
'return_code'
=>
'SUCCESS'
,
'appid'
=>
$weixinpay
[
'appid'
],
'mch_id'
=>
$weixinpay
[
'mchid'
],
'nonce_str'
=>
(
string
)
$result
->
nonce_str
,
'prepay_id'
=>
(
string
)
$result
->
prepay_id
,
'result_code'
=>
'SUCCESS'
,
'sign'
=>
''
];
$return
[
'sign'
]
=
Utils
::
makeWeixinPaySign
(
$return
,
$weixinpay
[
'key'
]);
return
\Yii
::
createObject
([
'class'
=>
'yii\web\Response'
,
'format'
=>
\yii\web\Response
::
FORMAT_XML
,
'formatters'
=>
[
\yii\web\Response
::
FORMAT_XML
=>
[
'class'
=>
'yii\web\XmlResponseFormatter'
,
'rootTag'
=>
'xml'
,
//根节点
],
],
'data'
=>
$return
]);
// var_dump(Yii::$app->request->post());
// $log = \Yii::$app->log->getLogger();
// $log->log(json_encode($data),Logger::LEVEL_ERROR);
}
public
function
actionIndex
(){
return
$this
->
render
(
'index'
);
}
}
opcache_invalidate
(
__FILE__
);
\ No newline at end of file
src/frontend/views/home/index.php
View file @
6cced394
...
@@ -14,7 +14,6 @@
...
@@ -14,7 +14,6 @@
data-setup=
'{"example_option":true,"autoplay":false,"language":"zh-CN"}'
>
data-setup=
'{"example_option":true,"autoplay":false,"language":"zh-CN"}'
>
<source
src=
"http://dev.qdn.pp.cc/object/test-3.mp4"
type=
"video/mp4"
/>
<source
src=
"http://dev.qdn.pp.cc/object/test-3.mp4"
type=
"video/mp4"
/>
</video>
</video>
</p>
</p>
...
...
src/frontend/views/test/index.php
0 → 100644
View file @
6cced394
<?php
/**
* Created by PhpStorm.
* User: xiabin
* Date: 2016/10/13
* Time: 下午5:32
*/
use
yii\helpers\Url
;
?>
<img
src=
"
<?=
Url
::
to
([
'home/weixin-pay-qrcode'
])
?>
"
/>
src/frontend/views/user-center/info.php
View file @
6cced394
...
@@ -48,7 +48,7 @@ $url = Yii::$app->qiniu->storages['public']['url'];
...
@@ -48,7 +48,7 @@ $url = Yii::$app->qiniu->storages['public']['url'];
<div
class=
"upload-avatar"
>
<div
class=
"upload-avatar"
>
<img
id=
"avatar-uploader"
<img
id=
"avatar-uploader"
src=
"
<?php
echo
\yii\bootstrap\Html
::
encode
(
Yii
::
$app
->
user
->
identity
->
avatar
===
''
?
\frontend\assets\AppAsset
::
getStaticUrl
(
'img/avatar.jpg'
)
:
$url
.
Yii
::
$app
->
user
->
identity
->
avatar
)
?>
"
>
src=
"
<?php
echo
\yii\bootstrap\Html
::
encode
(
Yii
::
$app
->
user
->
identity
->
avatar
===
''
?
\frontend\assets\AppAsset
::
getStaticUrl
(
'img/avatar.jpg'
)
:
$url
.
Yii
::
$app
->
user
->
identity
->
avatar
.
'-m.avatar'
)
?>
"
>
</div>
</div>
<div
class=
"type-name m-b-20"
>
<?=
\yii\bootstrap\Html
::
encode
(
Yii
::
$app
->
user
->
identity
->
username
)
?>
</div>
<div
class=
"type-name m-b-20"
>
<?=
\yii\bootstrap\Html
::
encode
(
Yii
::
$app
->
user
->
identity
->
username
)
?>
</div>
...
...
src/frontend/web/js/home/index.js
View file @
6cced394
...
@@ -13,6 +13,6 @@ videojs("example_video_1").ready(function () {
...
@@ -13,6 +13,6 @@ videojs("example_video_1").ready(function () {
var
myPlayer
=
this
;
var
myPlayer
=
this
;
// EXAMPLE: Start playing the video.
// EXAMPLE: Start playing the video.
myPlayer
.
play
();
//
myPlayer.play();
});
});
\ No newline at end of file
src/test.php
0 → 100644
View file @
6cced394
<?php
/**
* Created by PhpStorm.
* User: xiabin
* Date: 2016/10/13
* Time: 上午10:38
*/
var_dump
(
function_exists
(
'fnmatch'
));
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment