Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mall.oytour.com
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄奎
mall.oytour.com
Commits
482452b2
Commit
482452b2
authored
Aug 14, 2020
by
黄奎
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://gitlab.oytour.com/Kui2/mall.oytour.com
parents
93aa47df
3d7a230d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
116 additions
and
0 deletions
+116
-0
Config.cs
Mall.Common/Config.cs
+12
-0
PayUtil.cs
Mall.WindowsService/Helper/PayUtil.cs
+103
-0
appsettings.json
Mall.WindowsService/appsettings.json
+1
-0
No files found.
Mall.Common/Config.cs
View file @
482452b2
...
...
@@ -565,5 +565,17 @@ namespace Mall.Common
return
ReadConfigKey
(
"PropertyDB"
);
}
}
/// <summary>
/// 服务获取微信支付证书路径
/// </summary>
public
static
string
PayCertificateUrl
{
get
{
return
ReadConfigKey
(
"PayCertificateUrl"
);
}
}
}
}
\ No newline at end of file
Mall.WindowsService/Helper/PayUtil.cs
0 → 100644
View file @
482452b2
using
Mall.Common
;
using
Mall.Common.Plugin
;
using
Mall.Model.Extend.User
;
using
Mall.WeChat.Helper
;
using
Microsoft.AspNetCore.Http
;
using
System
;
using
System.Collections.Generic
;
using
System.Globalization
;
using
System.IO
;
using
System.Text
;
using
System.Web
;
using
System.Xml.Linq
;
namespace
Mall.WindowsService.Helper
{
public
class
PayUtil
{
/// <summary>
/// 企业付款
/// </summary>
/// <param name="sOrderNo"></param>
/// <param name="sProductName"></param>
/// <param name="dPrice"></param>
/// <param name="CustomerId"></param>
/// <param name="openid"></param>
/// <returns></returns>
public
static
bool
GetTransfersOrder
(
string
sOrderNo
,
decimal
dPrice
,
string
CustomerId
,
string
openid
,
RB_MiniProgram_Extend
model
,
IHttpContextAccessor
_accessor
,
string
Remark
=
""
)
{
if
(!
System
.
IO
.
File
.
Exists
(
Path
.
Combine
(
Config
.
PayCertificateUrl
,
"App_Data/Certs/WeChatApp/"
+
model
.
WeChatPayCertificateUrl
)))
{
return
false
;
}
var
req
=
new
Common
.
Pay
.
WeChatPat
.
RequestHandler
();
req
.
SetKey
(
model
.
WeChatApiSecret
);
req
.
SetParameter
(
"mch_appid"
,
model
.
MiniAppId
);
//微信开放平台审核通过的应用APPID
req
.
SetParameter
(
"mchid"
,
model
.
WeChatPayMerchants
);
//微信支付分配的商户号
req
.
SetParameter
(
"nonce_str"
,
GetNoncestr
());
//随机字符串,不长于32位
req
.
SetParameter
(
"partner_trade_no"
,
sOrderNo
);
//商户订单号,需保持唯一性(只能是字母或者数字,不能包含有其它字符)
req
.
SetParameter
(
"openid"
,
openid
);
req
.
SetParameter
(
"check_name"
,
"NO_CHECK"
);
req
.
SetParameter
(
"amount"
,
(
dPrice
*
100
).
ToString
(
"f0"
));
req
.
SetParameter
(
"desc"
,
Remark
==
""
?
"赞羊商城佣金提现"
:
Remark
);
req
.
SetParameter
(
"sign"
,
req
.
CreateMd5Sign
(
_accessor
,
model
.
WeChatApiSecret
));
var
reqXml
=
req
.
ParseXml
();
var
result
=
Common
.
Pay
.
WeChatPat
.
HttpHelper
.
Post
(
new
Common
.
Pay
.
WeChatPat
.
Model
.
HttpParam
()
{
Url
=
"https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers"
,
PostParam
=
reqXml
,
Encoding
=
Common
.
Pay
.
WeChatPat
.
HttpHelper
.
GetRequestEncoding
(
_accessor
.
HttpContext
.
Request
),
CertPath
=
Path
.
Combine
(
Config
.
PayCertificateUrl
,
"App_Data/Certs/WeChatApp/"
+
model
.
WeChatPayCertificateUrl
),
//"App_Data/Certs/WeChatApp/apiclient_cert.p12"),// model.WeChatPayCertificateUrl,
CertPwd
=
model
.
WeChatPayMerchants
//证书密码默认为您的商户ID
});
var
xe
=
XElement
.
Parse
(
result
,
LoadOptions
.
SetLineInfo
);
var
returnCode
=
xe
.
GetElement
(
"return_code"
).
Value
;
var
resultCode
=
xe
.
GetElement
(
"result_code"
).
Value
;
if
(
returnCode
.
Equals
(
"SUCCESS"
)
&&
resultCode
.
Equals
(
"SUCCESS"
))
{
return
true
;
}
return
false
;
}
/// <summary>
/// 获取随机字符串
/// </summary>
/// <returns></returns>
public
static
string
GetNoncestr
()
{
var
random
=
new
Random
();
return
SecurityHelper
.
MD5EncryptWeChat
(
random
.
Next
(
1000
).
ToString
(
CultureInfo
.
InvariantCulture
),
"GBK"
);
}
/// <summary>
/// 获取时间戳
/// </summary>
/// <returns></returns>
public
static
string
GetTimestamp
()
{
var
ts
=
DateTime
.
UtcNow
-
new
DateTime
(
1970
,
1
,
1
,
0
,
0
,
0
,
0
);
return
Convert
.
ToInt64
(
ts
.
TotalSeconds
).
ToString
(
CultureInfo
.
InvariantCulture
);
}
/// <summary>
/// 对字符串进行URL编码
/// </summary>
/// <param name="instr"></param>
/// <param name="charset">默认值:utf-8</param>
/// <returns></returns>
public
static
string
UrlEncode
(
string
instr
,
string
charset
)
{
if
(
instr
==
null
||
instr
.
Trim
()
==
""
)
return
""
;
var
res
=
HttpUtility
.
UrlEncode
(
instr
,
!
string
.
IsNullOrWhiteSpace
(
charset
)
?
Encoding
.
GetEncoding
(
charset
)
:
Encoding
.
GetEncoding
(
"utf-8"
));
return
res
;
}
}
}
Mall.WindowsService/appsettings.json
View file @
482452b2
...
...
@@ -39,6 +39,7 @@
"RebornDMC"
:
"reborn_dmc"
,
"IncomeFinanceApi"
:
"http://192.168.2.16:8083/api/Mall/InsertFinanceBatchForMallIn"
,
"PaymentFinanceApi"
:
"http://192.168.2.16:8083/api/Mall/InsertFinanceBatchForMallOut"
,
"PayCertificateUrl"
:
"D:/project/GitProject/Shopping/Mall.WebApi/"
,
"SettlementRate"
:
"0.60"
,
//
"FinanceKey"
:
"FinanceMallInsertToERPViitto2020"
,
"FinanceKey"
:
"FinanceMallInsertToERPViitto2020"
,
...
...
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