关闭订单接口


关闭订单接口只能针对30天以内的订单

关闭已经发起的订单,请求方式为POST

特别提示:订单发起后,并非一定要关闭


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

请求参数:

字段名称 字段类型 必填参数 说明
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) Y PAYJS 平台订单号
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->close($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->close($data);

print_r($result);

python

# !/usr/bin/env Python3
# -*- coding: utf-8 -*-

import requests
import hashlib
from urllib.parse import urlencode,unquote
'''
关闭订单接口
'''
payjs_order_id = '' # PAYJS 平台订单号
key = ''  # 填写通信密钥

order = {
    'payjs_order_id'    : payjs_order_id
}

# 构造签名函数
def sign(attributes,key):
    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,key)
request_url = "https://payjs.cn/api/close"
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/close", "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': '123456789'     //PAYJS 平台订单号
};
pay.close(params,function (msg) {
  console.log(msg);
  /**TODO 这里处理业务逻辑 */
});

java

// 完整代码:https://github.com/payjs-cn/demo-java
public Object Close() {

    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.closeUrl, 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.close(param);

powered by Gitbook最后更新: 2020-09-21