退款接口


对已经支付的订单发起退款,请求方式为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 微信支付订单号
sign string(32) Y 数据签名 详见签名算法

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


退款接口演示代码:

https://gist.github.com/payjscn/8759b682fbbca89cb395f4fb8fe8d9d1

<?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);

php

<?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))
}

powered by Gitbook最后更新: 2020-07-28