Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
5
51business
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
方斌
51business
Commits
287514a0
Commit
287514a0
authored
Jun 03, 2020
by
任国军
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add wechat notify
parent
5199994f
Pipeline
#24333
passed with stage
in 4 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
16 deletions
+16
-16
test.js
app/controller/common/test.js
+2
-11
wechat.js
app/controller/course/v5/wechat.js
+1
-0
wechat.js
app/service/course/v5/wechat.js
+13
-5
No files found.
app/controller/common/test.js
View file @
287514a0
...
...
@@ -4,17 +4,8 @@ const xml2js = require('xml2js');
const
Controller
=
require
(
'egg'
).
Controller
;
class
TestController
extends
Controller
{
async
test
()
{
this
.
ctx
.
set
(
'content-type'
,
'text/xml'
);
const
data
=
{
MsgType
:
'transfer_customer_service'
,
ToUserName
:
'to'
,
FromUserName
:
'from'
,
CreateTime
:
parseInt
(
new
Date
()
/
1000
),
};
const
builder
=
new
xml2js
.
Builder
({
rootName
:
'xml'
});
let
xml
=
builder
.
buildObject
(
data
);
xml
=
'<xml><ToUserName><![CDATA[$openid]]></ToUserName><FromUserName><![CDATA[$appId]]></FromUserName><CreateTime>$createTine</CreateTime><MsgType><![CDATA[transfer_customer_service]]></MsgType></xml>'
;
this
.
ctx
.
body
=
xml
;
const
ret
=
await
this
.
service
.
course
.
v5
.
wechat
.
pay
({});
this
.
ctx
.
success
(
ret
);
}
}
module
.
exports
=
TestController
;
app/controller/course/v5/wechat.js
View file @
287514a0
...
...
@@ -93,6 +93,7 @@ class WechatController extends Controller {
xmlData
+=
'<return_msg><![CDATA[OK]]></return_msg>'
;
xmlData
+=
'</xml>'
;
ctx
.
body
=
xmlData
;
console
.
logger
.
info
(
ctx
.
request
.
body
);
return
ctx
.
body
;
}
}
...
...
app/service/course/v5/wechat.js
View file @
287514a0
...
...
@@ -314,17 +314,23 @@ class WechatService extends Service {
const
appId
=
'wx07a5f0ed5bdf4751'
;
const
mchId
=
'1596633771'
;
const
key
=
'xuepenQuXuanKeweixinzhifu2020063'
;
const
nonce_str
=
ctx
.
helper
.
md5
(
moment
().
millisecond
()).
s
p
lice
(
0
,
16
);
const
nonce_str
=
ctx
.
helper
.
md5
(
moment
().
millisecond
()).
slice
(
0
,
16
);
const
body
=
input
.
body
||
'趣选课-测试'
;
const
out_trade_no
=
'2020060315300001'
;
const
total_fee
=
'
0.0
1'
;
const
spbill_create_ip
=
ctx
.
helper
.
getClientIP
();
const
total_fee
=
'1'
;
const
spbill_create_ip
=
ctx
.
helper
.
getClientIP
()
||
'127.0.0.1'
;
const
notify_url
=
'https://uat-nginx.jianbing.com/51business/api/course/v5/wechat/pay/notify'
;
const
trade_type
=
'JSAPI'
;
const
openid
=
'ofaz74vASbOyxwS1hyxrmQjYatlU'
;
// 签名
const
sign
=
ctx
.
helper
.
md5
(
`appid=
${
appId
}
&body=
${
body
}
&mch_id=
${
mchId
}
&nonce_str=
${
nonce_str
}
¬ify_url=
${
notify_url
}
&out_trade_no=
${
out_trade_no
}
&spbill_create_ip=
${
spbill_create_ip
}
&total_fee=
${
total_fee
}
&trade_type=
${
trade_type
}
&key=
${
key
}
`
);
sign
.
toUpperCase
();
const
arr
=
[
`appid=
${
appId
}
`
,
`body=
${
body
}
`
,
`mch_id=
${
mchId
}
`
,
`nonce_str=
${
nonce_str
}
`
,
`notify_url=
${
notify_url
}
`
,
`out_trade_no=
${
out_trade_no
}
`
,
`spbill_create_ip=
${
spbill_create_ip
}
`
,
`total_fee=
${
total_fee
}
`
,
`trade_type=
${
trade_type
}
`
,
`openid=
${
openid
}
`
];
arr
.
sort
();
let
sign
=
ctx
.
helper
.
md5
(
arr
.
join
(
'&'
)
+
`&key=
${
key
}
`
);
console
.
log
(
arr
.
join
(
'&'
)
+
`&key=
${
key
}
`
);
sign
=
sign
.
toUpperCase
();
console
.
log
(
sign
);
// 组装xml数据
let
xmlData
=
'<xml>'
;
...
...
@@ -337,11 +343,13 @@ class WechatService extends Service {
xmlData
+=
'<spbill_create_ip>'
+
spbill_create_ip
+
'</spbill_create_ip>'
;
xmlData
+=
'<total_fee>'
+
total_fee
+
'</total_fee>'
;
xmlData
+=
'<trade_type>'
+
trade_type
+
'</trade_type>'
;
xmlData
+=
'<openid>'
+
openid
+
'</openid>'
;
xmlData
+=
'<sign>'
+
sign
+
'</sign>'
;
xmlData
+=
'</xml>'
;
const
ret
=
request
({
url
:
'https://api.mch.weixin.qq.com/pay/unifiedorder'
,
method
:
'POST'
,
body
:
xmlData
},
function
(
err
,
response
,
body
)
{
if
(
!
err
&&
response
.
statusCode
===
200
)
{
console
.
log
(
'result:'
);
console
.
log
(
body
);
return
body
;
}
...
...
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