-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.clj
42 lines (40 loc) · 1.44 KB
/
core.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
(ns clj-wxpay.core
(:import [java.util HashMap Map]
[com.github.wxpay.sdk WXPay WXPayConfig]))
(defn- wxpay-config
[{:keys [appid mch_id key cert]
:or {appid (System/getProperty "clj.wxpay.appid")
mch_id (System/getProperty "clj.wxpay.mch_id")
key (System/getProperty "clj.wxpay.key")}}]
(reify
WXPayConfig
(getAppID [_] appid)
(getMchID [_] mch_id)
(getKey [_] key)
(getCertStream [_] cert)
(getHttpConnectTimeoutMs [_] 10000)
(getHttpReadTimeoutMs [_] 20000)))
(defn request
"cmd:
- pay/unifiedorder
- pay/orderquery
- secapi/pay/reverse
- pay/closeorder
- secapi/pay/refund
- pay/refundquery
- pay/downloadbill
- payitil/report
- tools/shorturl
- tools/authcodetoopenid
"
[^String cmd params & {:keys [cert api connectTimeoutMs readTimeoutMs]
:or {api "https://api.mch.weixin.qq.com/"
connectTimeoutMs 10000
readTimeoutMs 20000}
:as config}]
(let [wxpay (new WXPay (wxpay-config config))
reqData (.fillRequestData wxpay (new HashMap ^Map params))
res (if cert
(. wxpay requestWithCert ^String (str api cmd) ^Map reqData ^int connectTimeoutMs ^int readTimeoutMs)
(. wxpay requestWithoutCert ^String (str api cmd) ^Map reqData ^int connectTimeoutMs ^int readTimeoutMs))]
(.processResponseXml wxpay res)))