npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

zhiji-fuyoupay

v1.0.7

Published

富友支付

Downloads

2

Readme

npm i zhiji-fuyoupay

/src/configuration.ts

import * as fuyou from 'zhiji-fuyoupay';

@Configuration({
  imports: [
    fuyou
  ],
})

配置 config

{
  "fuyou": {
    "publicKey": "string", //富友公钥
    "privateKey": "string", //私钥
    "url": "string", //请求 url
    "mchnt_cd": "string", //商户号
    "appid": "可选|string", //下单时优先使用传入的appid 小程序 appid
    "refund": "string" //退款请求 url
  }
}

FuyouService 文档

概述

FuyouService 类是一个用于与富友支付网关交互的 Node.js 服务。它提供了下单、处理退款和处理富友系统回调的方法。该服务使用 RSA 加密进行安全通信,并使用 Axios 进行 HTTP 请求。

依赖

该服务依赖以下外部库:

  • @midwayjs/core: 提供依赖注入和配置的装饰器。
  • @midwayjs/axios: 用于进行 HTTP 请求。
  • moment: 一个用于日期操作的库。
  • node-rsa: 一个用于 RSA 加密和解密的库。
  • iconv-lite: 一个用于字符编码转换的库。

接口

refundResponseDTO

interface refundResponseDTO {
  refund_fas_ssn: string;
  refund_amt: string | number;
  pay_order_id: string;
  mchnt_cd: string;
  refund_order_id: string;
  refund_order_date: string;
  pay_order_date: string;
  refund_fas_date: string;
  refund_st: string;
}

placeOrderDTO

interface placeOrderDTO {
  order_amt: number | string;
  openid?: string;
  appid?: string;
  order_id: string;
  notify_url: string;
  goods_name: string;
  goods_detail: string;
  order_pay_type?: string;
  order_date: string;
}

refundDTO

interface refundDTO {
  order_id: string;
  order_date: string;
  refund_amt: number | string; //退款金额
  refund_order_id: string; //退货单号
}

类: FuyouService

属性

  • fuyou: 富友的配置对象,通过 @Config('fuyou') 注入。
  • axios: HttpService 的实例,通过 @Inject() 注入。
  • logger: ILogger 的实例,通过 @Inject() 注入。

方法

request

async request(url: string, param: any, HOST: string = this.fuyou.url): Promise<any>

发送请求到富友 API。

  • 参数:

    • url: 接口 URL。
    • param: 请求参数。
    • HOST: 主机 URL(默认为 this.fuyou.url)。
  • 返回: 富友 API 的解密响应。

  • 抛出: 如果请求失败或响应代码不是 '0000',则抛出错误。

decrypt

decrypt(data: string): any

使用商户的私钥解密给定的字符串。

  • 参数:

    • data: 加密的数据。
  • 返回: 解密后的 JSON 对象。

placeOrder

async placeOrder(data: placeOrderDTO): Promise<any>

在富友支付网关下单。

  • 参数:

    • data: 订单详情。
  • 返回: 富友 API 的响应。

refund

async refund(data: refundDTO): Promise<refundResponseDTO>

处理退款请求。

  • 参数:

    • data: 退款详情。
  • 返回: 富友 API 的响应,类型为 refundResponseDTO

fuyouCallback

async fuyouCallback(data: any): Promise<any>

处理来自富友系统的回调。

  • 参数:

    • data: 回调数据。
  • 返回: 解密后的回调消息。

示例用法

配置

确保在应用配置文件中提供富友配置:

{
  "fuyou": {
    "url": "https://api.fuyou.com",
    "publicKey": "YOUR_PUBLIC_KEY",
    "privateKey": "YOUR_PRIVATE_KEY",
    "mchnt_cd": "YOUR_MERCHANT_CODE",
    "appid": "YOUR_APP_ID",
    "refund": "https://refund.fuyou.com"
  }
}

下单

const orderData: placeOrderDTO = {
  order_amt: 100,
  order_id: 'ORDER12345',
  notify_url: 'https://yourdomain.com/notify',
  goods_name: 'Product Name',
  goods_detail: 'Product Details',
  order_date: moment().format('YYYYMMDD'),
};

const fuyouService = new FuyouService();
const orderResponse = await fuyouService.placeOrder(orderData);
console.log(orderResponse);

处理退款

const refundData: refundDTO = {
  order_id: 'ORDER12345',
  order_date: '20240624',
  refund_amt: 50,
  refund_order_id: 'REFUND12345',
};

const refundResponse = await fuyouService.refund(refundData);
console.log(refundResponse);

处理回调

const callbackData = {
  message: 'ENCRYPTED_MESSAGE',
};

const callbackResponse = await fuyouService.fuyouCallback(callbackData);
console.log(callbackResponse);

结论

FuyouService 类提供了一个与富友支付网关交互的强大接口,能够安全地处理下单、退款和回调。确保正确设置配置,并安全地处理密钥等敏感信息。