Skip to content

Commit

Permalink
chore: improve misc
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden committed May 17, 2018
1 parent 34d4dd3 commit a406867
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 22 deletions.
46 changes: 31 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,25 @@
[![dependencies Status](https://david-dm.org/sigoden/wechatpay/status.svg)](https://david-dm.org/sigoden/wechatpay)
[![Known Vulnerabilities](https://snyk.io/test/github/sigoden/wechatpay/badge.svg?targetFile=package.json)](https://snyk.io/test/github/sigoden/wechatpay?targetFile=package.json)

## 初始化
## 开始使用

```js
var Pay = require('@sigoden/wechatpay');
var pfxContent = fs.readFileSync("<location-of-your-apiclient-cert.p12>")
var pay = new Pay(appid, mch_id, key, pfxContent);

pay.unifiedorder({
body: '腾讯充值中心-QQ会员充值',
out_trade_no: '1217752501201407033233368018',
total_fee: 888,
spbill_create_ip: '8.8.8.8',
notify_url: 'https://example.com/wechatpay/notify',
trade_type: 'JSAPI',
openid: 'oUpF8uMuAJO_M2pxb1Q9zNjWeS6o'
}, function(err, result) {
if (err) return callback(err);
console.log(pay.tidyOrderResult(result));
})
```

## 接口
Expand Down Expand Up @@ -93,13 +106,14 @@ pay.unifiedorder({
```

```
{ appId: 'wxb80e5bddb2d804f3',
timeStamp: 1526470270,
nonceStr: '6LSB219WG129E3OLD9JOT1QA5RSOTBHA',
package: 'prepare_id=wx201411101639507cbf6ffd8b0779950874',
signType: 'MD5',
paySign: 'B8EE9BEF040D445275AE937CB93DAA8B' }
{
appId: 'wxb80e5bddb2d804f3',
timeStamp: 1526470270,
nonceStr: '6LSB219WG129E3OLD9JOT1QA5RSOTBHA',
package: 'prepare_id=wx201411101639507cbf6ffd8b0779950874',
signType: 'MD5',
paySign: 'B8EE9BEF040D445275AE937CB93DAA8B'
}
```
#### 扫码 [&#128279;](https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=9_1)

Expand Down Expand Up @@ -139,13 +153,15 @@ pay.unifiedorder({
```

```
{ appid: 'wxb80e5bddb2d804f3',
partnerid: '1424712502',
prepareid: 'wx201411101639507cbf6ffd8b0779950874',
package: 'Sign=WXPay',
noncestr: '6LSB219WG129E3OLD9JOT1QA5RSOTBHA',
timestamp: 1526470270,
sign: '4B9580464280084A33C31546F65CAC9F' }
{
appid: 'wxb80e5bddb2d804f3',
partnerid: '1424712502',
prepareid: 'wx201411101639507cbf6ffd8b0779950874',
package: 'Sign=WXPay',
noncestr: '6LSB219WG129E3OLD9JOT1QA5RSOTBHA',
timestamp: 1526470270,
sign: '4B9580464280084A33C31546F65CAC9F'
}
```

#### H5 [&#128279;](https://pay.weixin.qq.com/wiki/doc/api/H5.php?chapter=9_20&index=1)
Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
"pay"
],
"main": "src/pay.js",
"directories": {
"test": "test"
},
"scripts": {
"coverall": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"lint": "eslint --ext=.js src test",
Expand Down
2 changes: 1 addition & 1 deletion src/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ exports.fromXML = function(str, callback) {
parser.parseString(str, callback);
};

exports.missFields = function(obj, requireFields) {
exports.checkFields = function(obj, requireFields) {
var missFields = [];
for (var i = 0; i < requireFields.length; i++) {
var field = requireFields[i];
Expand Down
4 changes: 2 additions & 2 deletions src/pay.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ Pay.prototype.refundQuery = Pay.prototype.refundquery;
Pay.prototype.downloadbill = function(options, callback) {
var requireFields = ["bill_date", "bill_type"];

var missFields = helper.missFields(options, requireFields);
var missFields = helper.checkFields(options, requireFields);
if (missFields.length > 0) {
var err = helper.createError(
"ArgumentError",
Expand Down Expand Up @@ -763,7 +763,7 @@ Pay.prototype.addCert = function(options) {
* 必须字段校验
*/
Pay.prototype.mustHaveFields = function(options, requireFields) {
var missFields = helper.missFields(options, requireFields);
var missFields = helper.checkFields(options, requireFields);
if (missFields.length > 0) {
throw helper.createError(
"ArgumentError",
Expand Down
2 changes: 1 addition & 1 deletion test/unit/helper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe("missFields", function() {
test("find missed fields", function() {
var obj = { a: 3, b: 4, c: 5 };
var requireFields = ["a", "e"];
expect(helper.missFields(obj, requireFields)).toEqual(["e"]);
expect(helper.checkFields(obj, requireFields)).toEqual(["e"]);
});
});

Expand Down

0 comments on commit a406867

Please sign in to comment.