# wcpay-notify-result

> A package to build a result string for wechat pay notify callback

Latest version **1.0.2** (published 2018-01-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install wcpay-notify-result
pnpm add wcpay-notify-result
yarn add wcpay-notify-result
bun add wcpay-notify-result
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2018-01-19 |
| First published | 2018-01-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Richard Libre |
| Maintainers | codinggirl |
| Keywords | wechat, pay, wx, wxpay, wcpay, xml, json, 微信, 微信支付, 应答, 微信支付应答, 微信支付服务器 |

## Links

- npm: https://www.npmjs.com/package/wcpay-notify-result
- Repository: https://github.com/codinggirl/wcpay-notify-result
- Homepage: https://github.com/codinggirl/wcpay-notify-result#readme
- Issues: https://github.com/codinggirl/wcpay-notify-result/issues
- npm.io page: https://npm.io/package/wcpay-notify-result

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.2 (latest) — 2018-01-19
- 1.0.1 — 2018-01-18
- 1.0.0 — 2018-01-18

## README

# wcpay-notify-result

Read by language:
[[Engish]](#en) [[简体中文]](#zh-CN)

<a id='en' name='en'></a>

## Description

A package to build a result string for wechat pay notify callback.

<a id='zh-CN' name='zh-CN'></a>

## 概述

一个收到微信支付服务器支付结果通知后，生成用于返回的应答字符串的库。

支付完成后，微信会把相关支付结果和用户信息发送给商户，商户需要接收处理，并返回应答。
这个包就是生成这个应答字符串信息用的。

## 安装

选择下列一种方式安装即可。

- 直接安装

```bash
npm i wcpay-notify-result
```
- 作为依赖项安装

```bash
npm i --save wcpay-notify-result
```

## 使用

商户程序在处理完支付核验业务逻辑后，需要给微信支付服务器返回相应的xml应答字符串。
以下3种情况，可根据实际选择使用。

- 简单处理

```javascript
var result = require('wcpay-notify-result')

// 这里是你的处理信息
// 当业务处理成功时，msg应当为空
// 否则会被当作失败
var msg = '...'
var reply = result.result(msg)
// 使用你自己的服务器相关方法返回结果
res.setHeader('content-type', 'application/xml; charset=utf-8')
res.send(reply)
```

- 处理成功

```javascript
var result = require('wcpay-notify-result')

// 直接视为处理成功
var reply = result.success()
// 使用你自己的服务器相关方法返回结果
res.setHeader('content-type', 'application/xml; charset=utf-8')
res.send(reply)
```

- 处理失败

```javascript
var result = require('wcpay-notify-result')

// 失败信息
var msg = '签名失败'
// 获取处理失败时，返回给服务器的xml字符串
var reply = result.fail(msg)
// 使用你自己的服务器相关方法返回结果
res.setHeader('content-type', 'application/xml; charset=utf-8')
res.send(reply)
```

## API

- `function (msg)`

`msg` 失败原因

- `function success()`

- `function fail(msg)`

`msg` 失败原因

## 其他方案

本节列出社区中相关问题的其他解决方案，供大家参考。

注：这些包由社区中的其他成员维护。

- tenpay - 微信支付 for nodejs 

[npm](https://www.npmjs.com/package/tenpay) 
[GitHub](https://github.com/befinal/node-tenpay) 

这个包通过中间件的形式对支付结果通知、退款结果通知进行处理。如果你觉得中间件比较方便，可以选择此包。

## 参考

微信支付开发文档：[支付结果通知](https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7)

## 协议

[MIT](LICENSE), see [LICENSE](LICENSE) file for detail.  
Copyright © 2018 Richard Libre.  
Copyright © 2018 LibreRose Studio.

---
_Source: https://npm.io/package/wcpay-notify-result · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
