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
4307aefd
Commit
4307aefd
authored
Oct 19, 2016
by
杨培
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
微信接入中
parent
dfc202a1
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
780 additions
and
27 deletions
+780
-27
ApiWeixin.php
src/common/libs/ApiWeixin.php
+195
-0
OAuth2.php
src/common/libs/OAuth2.php
+433
-0
Utils.php
src/common/libs/Utils.php
+17
-2
Member.php
src/common/models/Member.php
+6
-0
composer.lock
src/composer.lock
+6
-6
ClassesFilter.php
src/frontend/components/ClassesFilter.php
+8
-13
MyIncomeController.php
src/frontend/controllers/MyIncomeController.php
+56
-2
blank.php
src/frontend/views/layouts/blank.php
+26
-0
index.php
src/frontend/views/my-income/index.php
+11
-3
no-connection.gif
src/frontend/web/img/no-connection.gif
+0
-0
qrcode.jpg
src/frontend/web/img/qrcode.jpg
+0
-0
index.js
src/frontend/web/js/my-income/index.js
+20
-0
webpack.config.js
src/frontend/web/webpack.config.js
+2
-1
No files found.
src/common/libs/ApiWeixin.php
0 → 100644
View file @
4307aefd
<?php
/**
* 微信 API
*
* $Id$
*/
namespace
common\libs
;
class
ApiWeixin
extends
OAuth2
{
private
$token
;
protected
$_type
=
'weixin'
;
/**
* Set up the API params.
*
* @ignore
*/
protected
$host
=
'https://api.weixin.qq.com/'
;
protected
$format
=
'json'
;
public
$debug
=
false
;
public
function
__construct
(
$accessToken
=
null
,
$refreshToken
=
null
,
$openid
=
null
)
{
$config
=
\Yii
::
$app
->
params
[
'weixinpay'
];
//$this->token = $config['token'];
parent
::
__construct
(
$config
[
'appid'
],
$config
[
'appsecret'
],
$accessToken
,
$refreshToken
,
$openid
);
//不传递 AccessToken 时,默认使用 API AccessToken
if
(
$accessToken
===
null
)
{
$accessToken
=
$this
->
getClientAccessToken
();
parent
::
__construct
(
$config
[
'appid'
],
$config
[
'appsecret'
],
$accessToken
,
$refreshToken
,
$openid
);
}
$this
->
useragent
=
'PHP/'
.
PHP_VERSION
;
}
/**
* 设置 OAuth 认证需要的 Urls
*
* @ignore
*/
public
function
accessTokenURL
(
$type
)
{
if
(
$type
==
'client'
)
{
return
$this
->
host
.
'cgi-bin/token'
;
}
else
{
return
$this
->
host
.
'sns/oauth2/access_token'
;
}
}
public
function
authorizeURL
()
{
return
'https://open.weixin.qq.com/connect/oauth2/authorize'
;
}
public
function
getAuthorizeURLWrapped
(
$url
,
$state
=
''
)
{
return
$this
->
getAuthorizeURL
(
$url
,
'code'
,
'snsapi_userinfo'
,
$state
)
.
'#wechat_redirect'
;
}
/**
* 获取微信API客户端 AccessToken,已进行相应的缓存处理
*
* @throws OAuthException
* @return string
*/
public
function
getClientAccessToken
()
{
$k
=
'yy_wxapi_access_token'
;
$token
=
\Yii
::
$app
->
redis
->
get
(
$k
);
if
(
$token
!==
null
)
{
return
$token
;
}
$ret
=
$this
->
getAccessToken
(
'client'
);
if
(
isset
(
$ret
[
'access_token'
]))
{
\Yii
::
$app
->
redis
->
setex
(
$k
,
$ret
[
'expires_in'
]
-
8
,
$ret
[
'access_token'
]);
}
else
{
throw
new
OAuthException
(
'get client access token failed because: '
.
$ret
[
'errmsg'
]
.
'('
.
$ret
[
'errcode'
]
.
')'
);
}
return
$ret
[
'access_token'
];
}
/**
* 获取用于某些接口使用的 ticket,已作缓存处理
*
* @param string $type
* @throws OAuthException
* @return string
*/
public
function
getTicket
(
$type
=
'jsapi'
)
{
$k
=
'yy_wxapi_ticket_'
.
$type
;
$ticket
=
\Yii
::
$app
->
redis
->
get
(
'get'
,
$k
);
if
(
$ticket
!==
null
)
{
return
$ticket
;
}
$accessToken
=
$this
->
getClientAccessToken
();
$ret
=
$this
->
get
(
'cgi-bin/ticket/getticket'
,
array
(
'access_token'
=>
$accessToken
,
'type'
=>
$type
));
if
(
$ret
[
'errcode'
]
==
0
)
{
\Yii
::
$app
->
redis
->
setex
(
$k
,
$ret
[
'expires_in'
]
-
8
,
$ret
[
'ticket'
]);
}
else
{
throw
new
OAuthException
(
"get
$type
ticket failed because:
{
$ret
[
'errmsg'
]
}
(
{
$ret
[
'errcode'
]
}
)"
);
}
return
$ret
[
'ticket'
];
}
/**
* 获取关注者 openid 列表
*
* @param string $nextOpenId
* @return array
*/
public
function
getUser
(
$nextOpenId
=
''
)
{
return
$this
->
get
(
'cgi-bin/user/get'
,
array
(
'next_openid'
=>
$nextOpenId
));
}
/**
* 通过 openid 获取指定关注者信息
*
* @param $openId
* @return mixed
*/
public
function
userInfo
(
$openId
)
{
//snsapi_userinfo 方式获取信息
return
$this
->
get
(
'sns/userinfo'
,
array
(
'openid'
=>
$openId
,
'lang'
=>
'zh_CN'
));
//snsapi_base 方式获取信息
//return $this->get('cgi-bin/user/info', array('openid'=>$openId));
}
public
function
sendTemplateMessage
(
$openId
,
$templateId
,
$data
,
$url
=
''
,
$topColor
=
'#FF0000'
)
{
$data
=
array
(
'touser'
=>
$openId
,
'template_id'
=>
$templateId
,
'url'
=>
$url
,
'topcolor'
=>
$topColor
,
'data'
=>
$data
);
return
$this
->
post
(
'cgi-bin/message/template/send'
,
$data
);
}
/**
* 创建二维码 Ticket
*
* @param int|string $sceneIdOrStr 当使用永久字符串参数二维码时,此处为字符串 scene_str 值,否则是 scene_id 值
* @param string $actionName QR_SCENE:临时二维码,QR_LIMIT_SCENE:永久二维码,QR_LIMIT_STR_SCENE:永久字符串参数二维码
* @param int $expireSeconds 临时有效期,最长7天,604800秒
* @return mixed
*/
public
function
createQRCode
(
$sceneIdOrStr
,
$actionName
=
'QR_SCENE'
,
$expireSeconds
=
1800
)
{
$data
=
array
(
'expire_seconds'
=>
$expireSeconds
,
'action_name'
=>
$actionName
,
'action_info'
=>
array
()
);
if
(
$actionName
==
'QR_LIMIT_STR_SCENE'
)
{
$data
[
'action_info'
][
'scene_str'
]
=
$sceneIdOrStr
;
}
else
{
$data
[
'action_info'
][
'scene_id'
]
=
$sceneIdOrStr
;
}
return
$this
->
post
(
'cgi-bin/qrcode/create'
,
$data
);
}
/**
* 通过 Ticket 换取二维码
*
* @param $ticket
* @return mixed
*/
public
function
showQRCode
(
$ticket
)
{
return
'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket='
.
urlencode
(
$ticket
);
}
/**
* 发送 POST 请求
*
* 微信接口 POST 包体为 json 数据,此处进行封装
*
* @param string $url
* @param array $parameters
* @param bool $multi
* @return mixed
*/
protected
function
post
(
$url
,
$parameters
=
array
(),
$multi
=
false
)
{
!
$multi
&&
$parameters
=
json_encode
(
$parameters
);
return
parent
::
post
(
$url
,
$parameters
,
$multi
);
}
}
\ No newline at end of file
src/common/libs/OAuth2.php
0 → 100644
View file @
4307aefd
<?php
/**
* OAuth2 标准库
*
* $Id$
*/
namespace
common\libs
;
abstract
class
OAuth2
{
/**
* @ignore
*/
private
$client_id
;
private
$client_secret
;
private
$access_token
;
private
$refresh_token
;
private
$openid
;
/**
* Contains the last HTTP status code returned.
*
* @ignore
*/
private
$http_code
;
/**
* Set up the API root URL.
*
* @ignore
*/
protected
$host
=
''
;
/**
* Set host IP adress.
*
* @ignore
*/
protected
$ip
=
''
;
/**
* Set timeout default.
*
* @ignore
*/
protected
$timeout
=
8
;
/**
* Set connect timeout.
*
* @ignore
*/
protected
$connecttimeout
=
8
;
/**
* Verify SSL Cert.
*
* @ignore
*/
protected
$ssl_verifypeer
=
FALSE
;
/**
* Respons format.
*
* @ignore
*/
protected
$format
=
'json'
;
/**
* Decode returned json data.
*
* @ignore
*/
protected
$decode_json
=
TRUE
;
/**
* Contains the last HTTP headers returned.
*
* @ignore
*/
protected
$http_info
;
/**
* Set the useragnet.
*
* @ignore
*/
protected
$useragent
=
''
;
/**
* boundary of multipart
* @ignore
*/
protected
static
$boundary
=
''
;
/**
* print the debug info
*
* @ignore
*/
public
$debug
=
false
;
protected
$_type
;
/**
* Construct OAuth Params
*/
public
function
__construct
(
$client_id
,
$client_secret
,
$access_token
=
NULL
,
$refresh_token
=
NULL
,
$openid
=
null
)
{
$this
->
client_id
=
$client_id
;
$this
->
client_secret
=
$client_secret
;
$access_token
&&
$this
->
access_token
=
$access_token
;
$openid
&&
$this
->
openid
=
$openid
;
$refresh_token
&&
$this
->
refresh_token
=
$refresh_token
;
}
/**
* Set API URLS
*
* @ignore
*/
public
abstract
function
accessTokenURL
(
$type
);
public
abstract
function
authorizeURL
();
/**
* authorize接口
*
* @param string $url 授权后的回调地址,站外应用需与回调地址一致,站内应用需要填写canvas page的地址
* @param string $response_type 支持的值包括 code 和token 默认值为code
* @param string $scope 应用授权作用域
* @param string $state 用于保持请求和回调的状态。在回调时,会在Query Parameter中回传该参数
* @param array $addon 额外参数
* @return array
*/
public
function
getAuthorizeURL
(
$url
,
$response_type
=
'code'
,
$scope
=
''
,
$state
=
''
,
$addon
=
array
())
{
$params
=
array
();
if
(
$this
->
_type
==
'weixin'
)
{
$params
[
'appid'
]
=
$this
->
client_id
;
}
else
{
$params
[
'client_id'
]
=
$this
->
client_id
;
}
$params
[
'redirect_uri'
]
=
$url
;
$params
[
'response_type'
]
=
$response_type
;
$scope
&&
$params
[
'scope'
]
=
$scope
;
$state
&&
$params
[
'state'
]
=
$state
;
$addon
&&
$params
+=
$addon
;
return
$this
->
authorizeURL
()
.
'?'
.
http_build_query
(
$params
);
}
/**
* access_token接口
*
* @param string $type 请求的类型
* @param array $keys 其他参数
* @return array
* @throws OAuthException
*/
public
function
getAccessToken
(
$type
=
'code'
,
$keys
=
array
())
{
$params
=
array
();
if
(
$this
->
_type
==
'weixin'
)
{
$method
=
'GET'
;
$params
[
'appid'
]
=
$this
->
client_id
;
$params
[
'secret'
]
=
$this
->
client_secret
;
}
else
{
$method
=
'POST'
;
$params
[
'client_id'
]
=
$this
->
client_id
;
$params
[
'client_secret'
]
=
$this
->
client_secret
;
}
switch
(
$type
)
{
case
'token'
:
$params
[
'grant_type'
]
=
'refresh_token'
;
$params
[
'refresh_token'
]
=
$keys
[
'refresh_token'
];
unset
(
$keys
[
'refresh_token'
]);
break
;
case
'code'
:
$params
[
'grant_type'
]
=
'authorization_code'
;
$params
[
'code'
]
=
$keys
[
'code'
];
unset
(
$keys
[
'code'
]);
break
;
case
'password'
:
$params
[
'grant_type'
]
=
'password'
;
$params
[
'username'
]
=
$keys
[
'username'
];
$params
[
'password'
]
=
$keys
[
'password'
];
unset
(
$keys
[
'username'
],
$keys
[
'password'
]);
break
;
case
'client'
:
$params
[
'grant_type'
]
=
'client_credential'
;
break
;
default
:
throw
new
OAuthException
(
'wrong auth type'
);
}
//scope, redirect_uri
$keys
&&
$params
+=
$keys
;
$response
=
$this
->
oAuthRequest
(
$this
->
accessTokenURL
(
$type
),
$method
,
$params
);
$token
=
null
;
if
(
$this
->
_type
==
'tencent'
)
{
parse_str
(
$response
,
$token
);
}
else
{
$token
=
json_decode
(
$response
,
true
);
}
//此处 errmsg 并没有根据各种情况做判断,新浪为 error,微信为 errmsg
if
(
is_array
(
$token
)
&&
isset
(
$token
[
'access_token'
]))
{
$this
->
access_token
=
$token
[
'access_token'
];
isset
(
$token
[
'refresh_token'
])
&&
$this
->
refresh_token
=
$token
[
'refresh_token'
];
isset
(
$token
[
'openid'
])
&&
$this
->
openid
=
$token
[
'openid'
];
}
else
{
throw
new
OAuthException
(
"get access token failed."
.
$token
[
'errmsg'
]);
}
return
$token
;
}
/**
* GET wrappwer for oAuthRequest.
*
* @return mixed
*/
protected
function
get
(
$url
,
$parameters
=
array
())
{
$response
=
$this
->
oAuthRequest
(
$url
,
'GET'
,
$parameters
);
if
(
$this
->
format
===
'json'
&&
$this
->
decode_json
)
{
return
json_decode
(
$response
,
true
);
}
return
$response
;
}
/**
* POST wreapper for oAuthRequest.
*
* @return mixed
*/
protected
function
post
(
$url
,
$parameters
=
array
(),
$multi
=
false
)
{
$response
=
$this
->
oAuthRequest
(
$url
,
'POST'
,
$parameters
,
$multi
);
if
(
$this
->
format
===
'json'
&&
$this
->
decode_json
)
{
return
json_decode
(
$response
,
true
);
}
return
$response
;
}
/**
* DELTE wrapper for oAuthReqeust.
*
* @return mixed
*/
public
function
delete
(
$url
,
$parameters
=
array
())
{
$response
=
$this
->
oAuthRequest
(
$url
,
'DELETE'
,
$parameters
);
if
(
$this
->
format
===
'json'
&&
$this
->
decode_json
)
{
return
json_decode
(
$response
,
true
);
}
return
$response
;
}
/**
* Format and sign an OAuth / API request
*
* @ignore
* @param string $url
* @param string $method
* @param array|string $parameters
* @param bool $multi
* @return string
*/
protected
function
oAuthRequest
(
$url
,
$method
,
$parameters
,
$multi
=
false
)
{
if
(
strrpos
(
$url
,
'http://'
)
!==
0
&&
strrpos
(
$url
,
'https://'
)
!==
0
)
{
$url
=
$this
->
host
.
$url
;
$this
->
_type
==
'sina'
&&
$url
.=
".
{
$this
->
format
}
"
;
}
$headers
=
$oauth
=
array
();
if
(
$this
->
access_token
)
{
switch
(
$this
->
_type
)
{
case
'tencent'
:
$oauth
[
'access_token'
]
=
$this
->
access_token
;
$oauth
[
'oauth_consumer_key'
]
=
$this
->
client_id
;
$oauth
[
'openid'
]
=
$this
->
openid
;
$oauth
[
'oauth_version'
]
=
'2.a'
;
$oauth
[
'scope'
]
=
'all'
;
$oauth
[
'clientip'
]
=
$parameters
[
'clientip'
];
break
;
case
'sina'
:
$headers
[]
=
'Authorization: OAuth2 '
.
$this
->
access_token
;
break
;
case
'weixin'
:
$oauth
[
'access_token'
]
=
$this
->
access_token
;
break
;
}
}
//腾讯使用 CURL 近期总是容易出现 SSL 证书问题导致请求中断
//使用 fsockopen 便无此问题,原因与我们的服务器环境有很大关系,暂时使用 socket 方式
//$http = $this->_type == 'tencent' ? 'http_socket' : 'http_curl';
$func
=
'http_curl'
;
if
(
$method
==
'GET'
)
{
$url
.=
'?'
.
http_build_query
(
$oauth
+
$parameters
);
$body
=
null
;
}
else
{
$url
.=
'?'
.
http_build_query
(
$oauth
);
if
(
is_array
(
$parameters
)
||
is_object
(
$parameters
))
{
if
(
!
$multi
)
{
$body
=
http_build_query
(
$parameters
);
$headers
[]
=
'Content-Type: application/x-www-form-urlencoded'
;
}
else
{
$body
=
self
::
build_http_query_multi
(
$parameters
);
$headers
[]
=
'Content-Type: multipart/form-data; boundary='
.
self
::
$boundary
;
}
}
else
{
$body
=
$parameters
;
}
}
return
$this
->
http
(
$url
,
$method
,
$body
,
$headers
);
}
/**
* Make an HTTP request
*
* @return string API results
* @ignore
*/
private
function
http
(
$url
,
$method
,
$postfields
=
NULL
,
$headers
=
array
())
{
$ci
=
curl_init
();
/* Curl settings */
curl_setopt
(
$ci
,
CURLOPT_USERAGENT
,
$this
->
useragent
);
curl_setopt
(
$ci
,
CURLOPT_CONNECTTIMEOUT
,
$this
->
connecttimeout
);
curl_setopt
(
$ci
,
CURLOPT_TIMEOUT
,
$this
->
timeout
);
curl_setopt
(
$ci
,
CURLOPT_RETURNTRANSFER
,
TRUE
);
curl_setopt
(
$ci
,
CURLOPT_SSL_VERIFYPEER
,
$this
->
ssl_verifypeer
);
curl_setopt
(
$ci
,
CURLOPT_HEADERFUNCTION
,
array
(
$this
,
'getHeader'
));
curl_setopt
(
$ci
,
CURLOPT_HEADER
,
FALSE
);
switch
(
$method
)
{
case
'POST'
:
curl_setopt
(
$ci
,
CURLOPT_POST
,
TRUE
);
if
(
!
empty
(
$postfields
))
{
curl_setopt
(
$ci
,
CURLOPT_POSTFIELDS
,
$postfields
);
}
break
;
case
'DELETE'
:
curl_setopt
(
$ci
,
CURLOPT_CUSTOMREQUEST
,
'DELETE'
);
if
(
!
empty
(
$postfields
))
{
$url
=
"
{
$url
}
?
{
$postfields
}
"
;
}
}
curl_setopt
(
$ci
,
CURLOPT_URL
,
$url
);
curl_setopt
(
$ci
,
CURLOPT_HTTPHEADER
,
$headers
);
curl_setopt
(
$ci
,
CURLINFO_HEADER_OUT
,
TRUE
);
$response
=
curl_exec
(
$ci
);
$this
->
http_code
=
curl_getinfo
(
$ci
,
CURLINFO_HTTP_CODE
);
$this
->
http_info
=
curl_getinfo
(
$ci
);
curl_close
(
$ci
);
if
(
$this
->
debug
)
{
echo
'=====info====='
.
"
\r\n
"
;
print_r
(
$this
->
http_info
);
echo
$url
;
echo
"
\r\n
=====post data======
\r\n
"
;
var_dump
(
$postfields
);
echo
"
\r\n
=====response=====
\r\n
"
;
print_r
(
$response
);
exit
;
}
return
$response
;
}
/**
* Get the header info to store.
*
* @return int
* @ignore
*/
private
function
getHeader
(
$ch
,
$header
)
{
$i
=
strpos
(
$header
,
':'
);
if
(
!
empty
(
$i
))
{
$key
=
str_replace
(
'-'
,
'_'
,
strtolower
(
substr
(
$header
,
0
,
$i
)));
$value
=
trim
(
substr
(
$header
,
$i
+
2
));
$this
->
http_header
[
$key
]
=
$value
;
}
return
strlen
(
$header
);
}
/**
* @ignore
*/
private
static
function
build_http_query_multi
(
$params
)
{
if
(
!
$params
)
return
''
;
uksort
(
$params
,
'strcmp'
);
$pairs
=
array
();
self
::
$boundary
=
$boundary
=
uniqid
(
'------------------'
);
$MPboundary
=
'--'
.
$boundary
;
$endMPboundary
=
$MPboundary
.
'--'
;
$multipartbody
=
''
;
foreach
(
$params
as
$parameter
=>
$value
)
{
if
(
$parameter
{
0
}
==
'@'
)
{
$parameter
=
substr
(
$parameter
,
1
);
$content
=
$value
[
2
];
$filename
=
$value
[
0
];
//$mime = $value[1];
$multipartbody
.=
$MPboundary
.
"
\r\n
"
;
$multipartbody
.=
'Content-Disposition: form-data; name="'
.
$parameter
.
'"; filename="'
.
$filename
.
'"'
.
"
\r\n
"
;
$multipartbody
.=
"Content-Type: image/unknown
\r\n\r\n
"
;
$multipartbody
.=
$content
.
"
\r\n
"
;
}
else
{
$multipartbody
.=
$MPboundary
.
"
\r\n
"
;
$multipartbody
.=
'content-disposition: form-data; name="'
.
$parameter
.
"
\"\r\n\r\n
"
;
$multipartbody
.=
$value
.
"
\r\n
"
;
}
}
$multipartbody
.=
$endMPboundary
;
return
$multipartbody
;
}
}
class
OAuthException
extends
\Exception
{}
src/common/libs/Utils.php
View file @
4307aefd
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
namespace
common\libs
;
namespace
common\libs
;
use
yii\base\ExitException
;
use
yii\web\Response
;
use
yii\web\Response
;
class
Utils
class
Utils
...
@@ -76,7 +76,22 @@ class Utils
...
@@ -76,7 +76,22 @@ class Utils
return
''
;
return
''
;
}
}
/**
* 显示提示信息页面
*
* @param string $message
* @throws ExitException
*/
public
static
function
showWarn
(
$message
)
{
\Yii
::
$app
->
controller
->
layout
=
'blank'
;
\Yii
::
$app
->
response
->
data
=
\Yii
::
$app
->
controller
->
render
(
'@app/views/site/warn'
,
[
'message'
=>
$message
]);
\Yii
::
$app
->
response
->
send
();
throw
new
ExitException
();
}
/**
/**
* 生成4-6位随机数
* 生成4-6位随机数
...
...
src/common/models/Member.php
View file @
4307aefd
...
@@ -139,6 +139,12 @@ class Member extends \yii\db\ActiveRecord
...
@@ -139,6 +139,12 @@ class Member extends \yii\db\ActiveRecord
}
}
}
}
/**
* 获取不同类型会员的数量统计
*
* @param int $userId
* @return array
*/
public
static
function
typeCount
(
$userId
)
public
static
function
typeCount
(
$userId
)
{
{
$data
=
self
::
find
()
->
select
(
'COUNT(1) AS count, type'
)
->
where
([
'user_id'
=>
$userId
])
->
groupBy
(
'type'
)
$data
=
self
::
find
()
->
select
(
'COUNT(1) AS count, type'
)
->
where
([
'user_id'
=>
$userId
])
->
groupBy
(
'type'
)
...
...
src/composer.lock
View file @
4307aefd
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
"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": "
553e6afb2f94832a2b21ea5d6301d656
",
"hash": "
479a584a432c765bda14b8e45493291a
",
"content-hash": "b2a9e1b6aa19ba113948022d2525b40b",
"content-hash": "b2a9e1b6aa19ba113948022d2525b40b",
"packages": [
"packages": [
{
{
...
@@ -357,16 +357,16 @@
...
@@ -357,16 +357,16 @@
},
},
{
{
"name": "guzzlehttp/guzzle",
"name": "guzzlehttp/guzzle",
"version": "6.2.
1
",
"version": "6.2.
2
",
"source": {
"source": {
"type": "git",
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "
3f808fba627f2c5b69e2501217bf31af349c1427
"
"reference": "
ebf29dee597f02f09f4d5bbecc68230ea9b08f60
"
},
},
"dist": {
"dist": {
"type": "zip",
"type": "zip",
"url": "https://packagist.phpcomposer.com/files/guzzle/guzzle/
3f808fba627f2c5b69e2501217bf31af349c1427
.zip",
"url": "https://packagist.phpcomposer.com/files/guzzle/guzzle/
ebf29dee597f02f09f4d5bbecc68230ea9b08f60
.zip",
"reference": "
3f808fba627f2c5b69e2501217bf31af349c1427
",
"reference": "
ebf29dee597f02f09f4d5bbecc68230ea9b08f60
",
"shasum": ""
"shasum": ""
},
},
"require": {
"require": {
...
@@ -415,7 +415,7 @@
...
@@ -415,7 +415,7 @@
"rest",
"rest",
"web service"
"web service"
],
],
"time": "2016-
07-15 17:22
:37"
"time": "2016-
10-08 15:01
:37"
},
},
{
{
"name": "guzzlehttp/promises",
"name": "guzzlehttp/promises",
...
...
src/frontend/components/ClassesFilter.php
View file @
4307aefd
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
namespace
frontend\components
;
namespace
frontend\components
;
use
common\libs\Utils
;
use
common\models\Classes
;
use
common\models\Classes
;
use
Yii
;
use
Yii
;
use
yii\base\ActionFilter
;
use
yii\base\ActionFilter
;
...
@@ -40,31 +41,25 @@ class ClassesFilter extends ActionFilter
...
@@ -40,31 +41,25 @@ class ClassesFilter extends ActionFilter
public
function
beforeAction
(
$action
)
{
public
function
beforeAction
(
$action
)
{
$uid
=
Yii
::
$app
->
user
->
getId
();
$uid
=
Yii
::
$app
->
user
->
getId
();
if
(
!
$uid
)
{
return
parent
::
beforeAction
(
$action
);
}
$class
=
Classes
::
getUserClass
(
$uid
);
$class
=
Classes
::
getUserClass
(
$uid
);
if
(
!
$class
)
{
if
(
!
$class
)
{
$this
->
showAlert
(
0
);
Utils
::
showWarn
(
'您还没有创建课堂,无法访问此页面!'
);
return
false
;
}
}
if
(
$this
->
_checkStatus
&&
$class
[
'status'
]
!=
Classes
::
STATUS_OK
)
{
if
(
$this
->
_checkStatus
&&
$class
[
'status'
]
!=
Classes
::
STATUS_OK
)
{
$this
->
showAlert
(
1
);
Utils
::
showWarn
(
'您提交的课堂资料尚未通过审核,无法访问此页面!'
);
return
false
;
}
}
if
(
property_exists
(
Yii
::
$app
->
controller
,
'classStatus'
))
{
if
(
property_exists
(
Yii
::
$app
->
controller
,
'classStatus'
))
{
Yii
::
$app
->
controller
->
classStatus
=
$class
;
Yii
::
$app
->
controller
->
classStatus
=
$class
;
}
}
return
parent
::
beforeAction
(
$action
);
}
public
function
showAlert
(
$exists
)
return
parent
::
beforeAction
(
$action
);
{
Yii
::
$app
->
response
->
data
=
Yii
::
$app
->
view
->
renderFile
(
'@app/views/site/error.php'
,
[
'name'
=>
'提示消息'
,
'message'
=>
$exists
?
'您提交的课堂资料尚未通过审核,无法访问此页面!'
:
'您还没有创建课堂,无法访问此页面!'
]);
}
}
}
}
\ No newline at end of file
src/frontend/controllers/MyIncomeController.php
View file @
4307aefd
...
@@ -2,10 +2,14 @@
...
@@ -2,10 +2,14 @@
namespace
frontend\controllers
;
namespace
frontend\controllers
;
use
common\libs\Utils
;
use
common\models\Income
;
use
common\models\Income
;
use
dosamigos\qrcode\lib\Enum
;
use
frontend\components\ClassesFilter
;
use
frontend\components\ClassesFilter
;
use
Yii
;
use
Yii
;
use
yii\filters\AccessControl
;
use
yii\filters\AccessControl
;
use
yii\helpers\Url
;
use
yii\web\Response
;
class
MyIncomeController
extends
\yii\web\Controller
class
MyIncomeController
extends
\yii\web\Controller
{
{
...
@@ -26,9 +30,12 @@ class MyIncomeController extends \yii\web\Controller
...
@@ -26,9 +30,12 @@ class MyIncomeController extends \yii\web\Controller
'allow'
=>
true
,
'allow'
=>
true
,
'roles'
=>
[
'@'
]
'roles'
=>
[
'@'
]
]
]
]
],
'except'
=>
[
'weixin-bind'
,
'weixin-callback'
]
],
],
'classes'
=>
ClassesFilter
::
className
()
'classes'
=>
[
'class'
=>
ClassesFilter
::
className
()
]
];
];
}
}
...
@@ -47,4 +54,51 @@ class MyIncomeController extends \yii\web\Controller
...
@@ -47,4 +54,51 @@ class MyIncomeController extends \yii\web\Controller
return
$this
->
render
(
'index'
,
$ret
+
compact
(
'settled'
,
'notSettled'
));
return
$this
->
render
(
'index'
,
$ret
+
compact
(
'settled'
,
'notSettled'
));
}
}
public
function
actionWxbindQrcode
()
{
//生成随机的 key 防止被猜测到
$key
=
Yii
::
$app
->
security
->
generateRandomString
();
//记录绑定信息
Yii
::
$app
->
redis
->
setex
(
'yy_wxbind_'
.
$key
,
7200
,
serialize
([
'uid'
=>
Yii
::
$app
->
user
->
getId
()
]));
$url
=
Url
::
to
([
'my-income/weixin-bind'
,
'key'
=>
$key
],
true
);
//输出二维码图像
$response
=
Yii
::
$app
->
response
;
$response
->
format
=
Response
::
FORMAT_RAW
;
$response
->
headers
->
set
(
'Content-Type'
,
'image/jpeg'
);
\dosamigos\qrcode\QrCode
::
encode
(
$url
,
false
,
Enum
::
QR_ECLEVEL_L
,
7
,
2
,
false
,
Enum
::
QR_FORMAT_JPG
);
}
public
function
actionWeixinBind
()
{
$key
=
Yii
::
$app
->
request
->
get
(
'key'
,
''
);
if
(
!
$key
)
{
Utils
::
showWarn
(
'参数缺失!'
);
}
$data
=
Yii
::
$app
->
redis
->
get
(
'yy_wxbind_'
.
$key
);
if
(
!
$data
)
{
Utils
::
showWarn
(
'该地址已失效,请刷新页面后重新扫描!'
);
}
$data
=
unserialize
(
$data
);
$callbackUrl
=
Url
::
to
([
'my-income/weixin-callback'
],
true
);
$wx
=
new
\common\libs\ApiWeixin
();
echo
$wx
->
getAuthorizeURLWrapped
(
$callbackUrl
,
$key
);
}
public
function
actionWeixinCallback
()
{
}
}
}
src/frontend/views/layouts/blank.php
0 → 100644
View file @
4307aefd
<?php
/**
* @var $this \yii\web\View
* @var $content string
*/
use
yii\helpers\Html
;
$this
->
beginPage
()
?>
<!DOCTYPE html>
<html
lang=
"
<?=
\Yii
::
$app
->
language
?>
"
>
<head>
<meta
charset=
"
<?=
\Yii
::
$app
->
charset
?>
"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1"
>
<meta
http-equiv=
"X-UA-Compatible"
content=
"IE=edge,chrome=1"
>
<title>
<?=
(
$this
->
title
?
Html
::
encode
(
$this
->
title
)
.
'-'
:
''
)
?>
最课堂
</title>
<?php
$this
->
head
()
?>
</head>
<body>
<?php
$this
->
beginBody
();
echo
$content
;
$this
->
endBody
();
?>
</body>
</html>
<?php
$this
->
endPage
();
\ No newline at end of file
src/frontend/views/my-income/index.php
View file @
4307aefd
<?php
<?php
/* @var $this yii\web\View */
/**
* @var $this yii\web\View
* @var $data array
* @var $pagination \yii\data\Pagination
*/
use
frontend\assets\AppAsset
;
$this
->
title
=
'知识有价'
;
$this
->
title
=
'知识有价'
;
AppAsset
::
addScript
(
$this
,
'@web/assets/my_income.js'
);
?>
?>
<div
class=
"buy-recode-top"
>
<div
class=
"buy-recode-top"
>
<div
class=
"col-md-4"
>
<div
class=
"col-md-4"
>
<h3>
结算微信
</h3>
<h3>
结算微信
</h3>
<button
class=
"btn btn-save
"
>
绑定
</button>
<button
type=
"button"
class=
"btn btn-save"
@
click=
"bindWeixinClick
"
>
绑定
</button>
</div>
</div>
<div
class=
"col-md-4"
>
<div
class=
"col-md-4"
>
<h3>
已结算
</h3>
<h3>
已结算
</h3>
...
@@ -40,7 +48,7 @@ $this->title = '知识有价';
...
@@ -40,7 +48,7 @@ $this->title = '知识有价';
<td>
<?=
$row
[
'order'
][
'user'
][
'telephone'
]
?>
/
<?=
$row
[
'order'
][
'user'
][
'username'
]
?>
</td>
<td>
<?=
$row
[
'order'
][
'user'
][
'telephone'
]
?>
/
<?=
$row
[
'order'
][
'user'
][
'username'
]
?>
</td>
<td>
《
<?=
$row
[
'order'
][
'course'
][
'name'
]
?>
》
</td>
<td>
《
<?=
$row
[
'order'
][
'course'
][
'name'
]
?>
》
</td>
<td>
¥
<?=
$row
[
'order'
][
'credit'
]
?>
</td>
<td>
¥
<?=
$row
[
'order'
][
'credit'
]
?>
</td>
<td>
<?=
(
$row
[
'status'
]
?
'
未结算'
:
'已
结算'
)
?>
</td>
<td>
<?=
(
$row
[
'status'
]
?
'
已结算'
:
'未
结算'
)
?>
</td>
</tr>
</tr>
<?php
}
?>
<?php
}
?>
</tbody>
</tbody>
...
...
src/frontend/web/img/no-connection.gif
0 → 100644
View file @
4307aefd
6.54 KB
src/frontend/web/img/qrcode.jpg
0 → 100644
View file @
4307aefd
16.3 KB
src/frontend/web/js/my-income/index.js
0 → 100644
View file @
4307aefd
var
Vue
=
require
(
'vue'
);
var
layer
=
require
(
'layer-js'
);
var
vm
=
new
Vue
({
el
:
".buy-recode-top"
,
methods
:
{
bindWeixinClick
:
function
()
{
var
idx
=
layer
.
open
({
type
:
1
,
title
:
"绑定微信"
,
content
:
'<div class="qrcode-img"><img src="'
+
__BASE_URL__
+
'my-income/wxbind-qrcode" style="margin:0;height:auto;"><p>扫码后,请在手机端“确认”绑定</p></div>'
,
area
:
[
'320px'
,
'380px'
],
cancel
:
function
(
idx
)
{
layer
.
close
(
idx
);
this
.
content
.
show
();
}
});
}
}
});
\ No newline at end of file
src/frontend/web/webpack.config.js
View file @
4307aefd
...
@@ -24,7 +24,8 @@ var entry = {
...
@@ -24,7 +24,8 @@ var entry = {
home_index
:
[
js_dir
+
'/home/index.js'
],
home_index
:
[
js_dir
+
'/home/index.js'
],
home_video
:
[
js_dir
+
'/home/video.js'
],
home_video
:
[
js_dir
+
'/home/video.js'
],
course_publish
:
[
js_dir
+
'/my-course/publish.js'
],
course_publish
:
[
js_dir
+
'/my-course/publish.js'
],
teacher_form
:
[
js_dir
+
'/teacher-manager/form.js'
]
teacher_form
:
[
js_dir
+
'/teacher-manager/form.js'
],
my_income
:
[
js_dir
+
'/my-income/index.js'
]
};
};
var
config
=
{
var
config
=
{
...
...
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