Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
my-yaf-project
Project
Project
Details
Activity
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenchuanwen
my-yaf-project
Commits
cd2e0fb2
Commit
cd2e0fb2
authored
Jan 03, 2019
by
testshenbd
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'linqing' of git.shenbd.com:qm-develop/shenbd into master_dev
parents
1977320f
0d21c503
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
216 additions
and
161 deletions
+216
-161
OrderConfirmUtil.php
application/library/Order/OrderConfirmUtil.php
+13
-83
WechatCommon.php
application/library/Our/WechatCommon.php
+16
-1
OrderService.php
application/models/Business/Order/OrderService.php
+186
-76
sendTemplateMessage.php
scripts/crontab/order/sendTemplateMessage.php
+1
-1
No files found.
application/library/Order/OrderConfirmUtil.php
View file @
cd2e0fb2
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
namespace
Order
;
namespace
Order
;
use
Our\ApiConst
;
use
Our\ApiConst
;
use
Our\RedisHelper
;
use
Our\RedisHelper
;
use
Our\WechatCommon
;
/**
/**
...
@@ -709,8 +710,11 @@ class OrderConfirmUtil {
...
@@ -709,8 +710,11 @@ class OrderConfirmUtil {
\Error\ErrorModel
::
throwException
(
\Error\CodeConfigModel
::
failedUpdateFavoritesStoreForOrder
);
\Error\ErrorModel
::
throwException
(
\Error\CodeConfigModel
::
failedUpdateFavoritesStoreForOrder
);
}
}
$orderModel
->
db
->
doCommit
();
$orderModel
->
db
->
doCommit
();
$wechatCommon
=
WechatCommon
::
getInstance
();
$access_token
=
$wechatCommon
->
getAccessToken
();
//订单通过小程序表单提交过来
//订单通过小程序表单提交过来
if
(
$formId
&&
(
$access_token
=
$this
->
getLitAccesstoken
())
)
{
if
(
$formId
&&
$access_token
)
{
$settingDAO
=
\DAO\SettingModel
::
getInstance
();
$settingDAO
=
\DAO\SettingModel
::
getInstance
();
$msg_tpl
=
$settingDAO
->
getListCache
(
array
(
'wxapp_order_create_tpl'
))[
'wxapp_order_create_tpl'
];
$msg_tpl
=
$settingDAO
->
getListCache
(
array
(
'wxapp_order_create_tpl'
))[
'wxapp_order_create_tpl'
];
$goods_str
=
''
;
$goods_str
=
''
;
...
@@ -724,98 +728,24 @@ class OrderConfirmUtil {
...
@@ -724,98 +728,24 @@ class OrderConfirmUtil {
$openid
=
$authInfo
[
'openid'
];
$openid
=
$authInfo
[
'openid'
];
$req_data
=
array
(
'touser'
=>
$openid
,
'template_id'
=>
$msg_tpl
,
'form_id'
=>
$formId
,
$req_data
=
array
(
'touser'
=>
$openid
,
'template_id'
=>
$msg_tpl
,
'form_id'
=>
$formId
,
'page'
=>
'pages/orders/
list/index'
,
'page'
=>
'pages/orders/
detail/index?id='
.
$orderId
,
'data'
=>
array
(
'data'
=>
array
(
'keyword1'
=>
array
(
'value'
=>
'下单成功'
),
'keyword1'
=>
array
(
'value'
=>
'下单成功'
),
'keyword2'
=>
array
(
'value'
=>
$order
[
'order_sn'
]),
'keyword2'
=>
array
(
'value'
=>
$order
[
'order_sn'
]),
'keyword3'
=>
array
(
'value'
=>
number_format
(
$order
[
'order_amount'
]
/
100
,
2
)
.
'元'
),
'keyword3'
=>
array
(
'value'
=>
number_format
(
$order
[
'order_amount'
]
/
100
,
2
)
.
'元'
),
'keyword4'
=>
array
(
'value'
=>
$order
[
'store_name'
]),
'keyword4'
=>
array
(
'value'
=>
$order
[
'store_name'
]),
'keyword5'
=>
array
(
'value'
=>
$goods_str
),
'keyword5'
=>
array
(
'value'
=>
$goods_str
),
));
));
// \Our\Log::getInstance()->write(json_encode($req_data), '/data/log/apptest');
// \Our\Log::getInstance()->write(json_encode($req_data), '/data/log/apptest');
$url
=
'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token='
;
$json
=
$wechatCommon
->
sendTemplateMessage
(
$access_token
,
$req_data
);
$result
=
$this
->
sendurl
(
$url
,
$access_token
,
json_encode
(
$req_data
),
'post'
);
// \Our\Log::getInstance()->write($json, '/data/log/apptest');
\Our\Log
::
getInstance
()
->
write
(
var_export
(
$result
,
true
),
'/data/log/apptest'
);
}
}
$this
->
opCacheInfo
();
$this
->
opCacheInfo
();
$this
->
pushMessage
();
$this
->
pushMessage
();
return
array
(
'needPayFlag'
=>
$needPayFlag
,
'paySn'
=>
$paySn
);
return
array
(
'needPayFlag'
=>
$needPayFlag
,
'paySn'
=>
$paySn
);
}
}
/**
* 获取小程序表单
* User: King <358887571@qq.com>
* Date: 2018/12/27 0027
* Time: 下午 3:15
*/
private
function
getLitAccesstoken
(){
$model_wx
=
\DAO\MbWxModel
::
getInstance
();
$weixin
=
$model_wx
->
getOne
(
'id,lit_appid,lit_appsecret,lit_accesstoken,lit_expirestime'
,
'id=1'
);
$access_token
=
''
;
if
(
!
$weixin
[
'lit_expirestime'
]
||
$weixin
[
'lit_expirestime'
]
<
time
())
{
$access_info
=
json_decode
(
file_get_contents
(
'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='
.
$weixin
[
'lit_appid'
]
.
'&secret='
.
$weixin
[
'lit_appsecret'
]),
true
);
if
(
isset
(
$access_info
[
'access_token'
]))
{
$access_token
=
$access_info
[
'access_token'
];
$update_data
=
array
();
$update_data
[
'lit_accesstoken'
]
=
$access_info
[
'access_token'
];
$update_data
[
'lit_expirestime'
]
=
TIMESTAMP
+
$access_info
[
'expires_in'
]
-
1800
;
$where
=
array
(
'id'
=>
$weixin
[
'id'
]);
$result
=
$model_wx
->
update
(
$update_data
,
$where
);
}
}
else
{
$access_token
=
$weixin
[
'lit_accesstoken'
];
}
return
$access_token
;
}
/**
* curl请求
* @param $url
* @param $access_token
* @param $data
* @param $method
*/
private
function
sendurl
(
$url
,
$access_token
=
''
,
$data
=
''
,
$method
=
'get'
,
$header
=
''
)
{
//
if
(
strtolower
(
$method
)
==
'post'
)
{
$curl
=
curl_init
();
curl_setopt
(
$curl
,
CURLOPT_URL
,
$url
.
$access_token
);
curl_setopt
(
$curl
,
CURLOPT_SSL_VERIFYPEER
,
FALSE
);
curl_setopt
(
$curl
,
CURLOPT_SSL_VERIFYHOST
,
FALSE
);
}
else
{
$curl
=
curl_init
(
$url
.
$access_token
);
}
if
(
$header
){
//设置头部信息
curl_setopt
(
$curl
,
CURLOPT_HTTPHEADER
,
$header
);
}
//$curl = curl_init($url.$access_token);
curl_setopt
(
$curl
,
CURLOPT_FAILONERROR
,
1
);
//设置允许页面重定向
curl_setopt
(
$curl
,
CURLOPT_FOLLOWLOCATION
,
1
);
//设置返回值赋给变量
curl_setopt
(
$curl
,
CURLOPT_RETURNTRANSFER
,
1
);
//设置操作时间
curl_setopt
(
$curl
,
CURLOPT_TIMEOUT
,
5
);
if
(
$method
==
'post'
){
if
(
!
$data
)
$data
=
''
;
// 使用post 请求
curl_setopt
(
$curl
,
CURLOPT_POST
,
1
);
// 设置请求参数
curl_setopt
(
$curl
,
CURLOPT_POSTFIELDS
,
$data
);
}
//开始事务
$r
=
curl_exec
(
$curl
);
curl_close
(
$curl
);
return
$r
;
}
public
function
pushMessage
(){
public
function
pushMessage
(){
if
(
$this
->
pushMessageOrders
){
if
(
$this
->
pushMessageOrders
){
$orderService
=
\Business\Order\OrderServiceModel
::
getInstance
();
$orderService
=
\Business\Order\OrderServiceModel
::
getInstance
();
...
...
application/library/Our/WechatCommon.php
100755 → 100644
View file @
cd2e0fb2
...
@@ -72,6 +72,21 @@ class WechatCommon
...
@@ -72,6 +72,21 @@ class WechatCommon
return
$jsonstr
;
return
$jsonstr
;
}
}
/**
* 发送模板消息
*
* @param $access_token token
* @param $req_data 请求数据数组
* User: King <358887571@qq.com>
* Date: 2019/1/2 0002
* Time: 下午 4:41
*/
public
function
sendTemplateMessage
(
$access_token
,
$req_data
)
{
$url
=
'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token='
.
$access_token
;
$result
=
$this
->
httpsPostJson
(
$url
,
$req_data
,
true
);
return
$result
;
}
public
function
httpsPostJson
(
$url
,
$data
=
''
,
$array
=
false
)
public
function
httpsPostJson
(
$url
,
$data
=
''
,
$array
=
false
)
{
{
...
@@ -127,4 +142,4 @@ class WechatCommon
...
@@ -127,4 +142,4 @@ class WechatCommon
return
self
::
$_instance
;
return
self
::
$_instance
;
}
}
}
}
\ No newline at end of file
application/models/Business/Order/OrderService.php
View file @
cd2e0fb2
This diff is collapsed.
Click to expand it.
scripts/crontab/order/sendTemplateMessage.php
View file @
cd2e0fb2
...
@@ -57,7 +57,7 @@ class cliOrderSendTemplateMessage extends basecli
...
@@ -57,7 +57,7 @@ class cliOrderSendTemplateMessage extends basecli
echo
"*** Debug mode ***
\n
"
;
echo
"*** Debug mode ***
\n
"
;
}
}
// Step: 02 检查是否已有相同CLI在运行中
// Step: 02 检查是否已有相同CLI在运行中
$lockDir
=
$this
->
_getBaseFileName
(
'order
SendTemplateMessage
'
);
$lockDir
=
$this
->
_getBaseFileName
(
'order'
);
if
(
!
$this
->
mkdirs
(
$lockDir
)){
if
(
!
$this
->
mkdirs
(
$lockDir
)){
echo
'****create dir fail ****'
;
echo
'****create dir fail ****'
;
exit
;
exit
;
...
...
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