退款接口


对已经支付的订单发起退款,请求方式为POST

请求地址:https://payjs.cn/api/refund

请求参数:

字段名称 字段类型 必填参数 说明
payjs_order_id string(32) Y PAYJS 平台订单号
sign string(32) Y 数据签名 详见签名算法

请求返回:

字段名称 字段类型 必填参数 说明
return_code int Y 1:退款成功 0:退款失败
return_msg string(32) Y 返回消息
payjs_order_id string(32) N PAYJS 平台订单号
out_trade_no string(32) N 用户侧订单号
transaction_id string(32) N 微信支付订单号
refund string(1) N 退款状态(订单若已退款则返回该字段,值为1)
sign string(32) Y 数据签名 详见签名算法

提示:成功退款的条件是,未结算款大于退款金额


退款演示代码

// 引入 payjs.class.php
// 项目地址:https://github.com/payjs-cn/phpsdk

include("payjs.class.php");

$mchid = '123456';
$key = 'xxxxxx';

$data = [
    "payjs_order_id" => '123123123',
];

$payjs = new Payjs($mchid, $key);
$result = $payjs->refund($data);

print_r($result);

php

// 引入 payjs.class.php
// 项目地址:https://github.com/payjs-cn/phpsdk

include("payjs.class.php");

$mchid = '123456';
$key = 'xxxxxx';

$data = [
    "payjs_order_id" => '123123123',
];

$payjs = new Payjs($mchid, $key);
$result = $payjs->refund($data);

print_r($result);

python

# !/usr/bin/env Python3
# -*- coding: utf-8 -*-
import requests
import time
import hashlib
from urllib.parse import urlencode,unquote
'''
退款接口
'''

mchid = ''                # 特写商户号
payjs_order_id = ''       # PAYJS 平台订单号
key = ''                  # 填写通信密钥

order = {
    'mchid'         : mchid,
    'payjs_order_id' : payjs_order_id
}

# 构造签名函数
def sign(attributes):
    attributes_new = {k: attributes[k] for k in sorted(attributes.keys())}
    return hashlib.md5((unquote(urlencode(attributes_new))+'&key='+key)
        .encode(encoding='utf-8')).hexdigest().upper()

order['sign'] = sign(order)
request_url = "https://payjs.cn/api/refund"
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=order,headers=headers)
if response:
    print(response.json())

go

package main

import (
    "fmt"
    "strings"
    "net/http"
    "net/url"
    "io/ioutil"
)

func main(){
    data := url.Values{"payjs_order_id":{"XXX"}, "sign":{"XXX"}}
    data2 := strings.NewReader(data.Encode())
    resp, err := http.Post("https://payjs.cn/api/refund", "application/x-www-form-urlencoded", data2)
    if err != nil {
        fmt.Println(err)
    }
    defer resp.Body.Close()
    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        // handle error
    }

    fmt.Println(string(body))
}

node

// 项目地址:https://github.com/payjs-cn/demo-nodejs
// 首先引入文件,并在config.js中配置商户号和通信密钥
var cfg = require("./config.js"); 
var pay = require("./pay.js");

//退款接口
var params = {
  'payjs_order_id': ''     //PAYJS 平台订单号
};
pay.refund(params,function (msg) {
  console.log(msg);
  /**TODO 这里处理业务逻辑 */
});

java

// 完整代码:https://github.com/payjs-cn/demo-java
public Object Refund() {
    Map<String,String> payData = new HashMap<>();
    payData.put("mchid", PayjsConfig.mchid);
    payData.put("payjs_order_id", "83432749"); // payjs订单号

    // 进行sign签名
    payData.put("sign", sign(payData, PayjsConfig.key));

    // 请求payjs获取数据
    String result = HttpsUtils.sendPost(PayjsConfig.refundUrl, JSON.toJSONString(payData),null);

    // 接口返回数据
    return JSON.parseObject(result);
}

csharp

// 完整项目地址:https://github.com/payjs-cn/sdk-csharp

Payjs pay = new Payjs("YOUR MCHID", "YOUR KEY");

Dictionary<string, string> param = new Dictionary<string, string>();
param["payjs_order_id"] = "2018xxxxxxx";

//返回原始json字符串
string jsonString = pay.refund(param);

powered by Gitbook最后更新: 2022-04-12