首页
> 计算机技术
> 后端开发
> Nim
Nim语言原生实现微信支付SDK
原创 lihf8515于2025年02月23日 17:54发表
来源:本站 阅读:132
微信支付功能有很多语言都有集成SDK,方便了开发支付功能。但是,Nim语言由于生态问题,还没有微信支付SDK,因此,笔者自己从零实现了一个Nim语言原生微信支付SDK(WeChat payment SDK for Nim.),详细源代码请访问github查看,https://github.com/lihf8515/wxpay
这里,我们将以一个简单的例子,说明如何使用该SDK,实现Nim语言的微信支付调用。
wxpay
WeChat payment SDK for Nim.
已经实现的功能:
- 付款码支付
- 申请退款
- 统一下单
- 关闭订单
- 下载对账单
- 订单查询
- 退款申请查询
- 交易保障
- 撤销订单
注意:编译时请使用 -d:ssl 以开启ssl支持
import tables | |
import wxpay | |
var results = OrderedTable[string, string]() | |
var input = OrderedTable[string, string]() | |
var config = OrderedTable[string, string]() | |
config["appid"] = "" | |
config["appsecret"] = "" | |
config["key"] = "" | |
config["mch_id"] = "" | |
config["notify_url"] = "" | |
config["proxy_host"] = "0.0.0.0" | |
config["proxy_port"] = "0" | |
config["report_level"] = "1" | |
config["sslcert_path"] = "cert/apiclient_cert.pem" | |
config["sslkey_path"] = "cert/apiclient_key.pem" | |
config["sign_type"] = "HMAC-SHA256" | |
input["auth_code"] = "138728953980228598" | |
input["body"] = "付款码支付测试" | |
input["total_fee"] = "1" | |
input["out_trade_no"] = "test00000001" | |
try: | |
if wxMicropay(input, config, results): | |
echo "支付成功" | |
echo results | |
else: | |
echo "支付失败" | |
echo results | |
except: | |
echo wxErrorMessage() | |
results.clear() | |
input.clear() | |
input["out_refund_no"] = "132564989589668" | |
input["out_trade_no"] = "test00000001" | |
input["refund_fee"] = "1" | |
input["total_fee"] = "1" | |
try: | |
if wxRefund(input, config, results): | |
echo "请求退款成功" | |
echo results | |
else: | |
echo "请求退款失败" | |
echo results | |
except: | |
echo wxErrorMessage() |
阅读排行榜