当用户从交易的模板组件发起退款后,抖音开平交易系统会给向开发者的服务发起请求,用于通知开发者用户发起退款,开发者响应时需要返回必填的信息。
注意流程图中红色线条的部分

客服退

| 基本信息 | |
|---|---|
| HTTP URL | 开发者通过设置回调地址设置的 refund_callback 路径 |
| HTTP Method | POST |
| 权限要求 | 无 |
| 名称 | 类型 | 是否必填 | 描述 | 示例 |
|---|---|---|---|---|
| app_id | string | 是 | 小程序的 appid | ttqweqw12312 |
| open_id | string | 是 | 用户 openid | 123123 |
| refund_id | string | 是 | 抖音开平侧退款单号 | ot1231313 |
| order_id | string | 是 | 抖音开平侧订单号 | ot1231312 |
| out_order_no | string | 是 | 开发者侧订单号 | 213123 |
| refund_total_amount | int64 | 是 | 退款总金额,单位分 | 100 |
| need_refund_audit | int8 | 是 | 是否需要退款审核: 1:需要退款审核 2:不需要退款审核 不需要退款审核,则无需再调用退款审核结果同步接口 | 1 |
| refund_audit_deadline | int64 | 否 | 退款审核的最后期限,超过该期限无需商家审核,自动退款,13 位时间戳,单位毫秒 通常是3天(从退款发起时间开始算) | 151231321231 |
| create_refund_time | int64 | 是 | 退款创建时间,13 位时间戳,单位毫秒 | 151231321230 |
| refund_source | int8 | 是 | 退款来源: 1:用户发起退款 3:过期自动退 4:抖音客服退款 5:预约失败自动退款 | 1 |
| cp_extra | string | 否 | cp 自定义字段,不支持二进制,长度 <= 2048byte | cp_extra |
| refund_reason | Array | 否 | 退款原因,退款原因有多个 | ["不喜欢"] |
| refund_description | string | 否 | 退款补充说明 | 想退款 |
| refund_item_detail | object | 否 | 退款商品单信息 注意:交易系统订单退款必传 |
| 名称 | 类型 | 是否必填 | 描述 | 示例值 |
|---|---|---|---|---|
| item_order_quantity | int64 | 是 | 用户需要退款多少个商品单 | 1 |
| item_order_detail | Array | 是 | 本次退款的商品单列表 |
| 名称 | 类型 | 是否必填 | 描述 | 示例值 |
|---|---|---|---|---|
| item_order_id | string | 是 | 抖音开平侧商品单号,商品单号在预下单接口同步给了开发者 | ot123134 |
| refund_amount | int | 是 | 该商品单退款金额 | 100 |
{
"app_id": "ttqweqw12312",
"open_id": "123123",
"refund_id": "ot123133",
"order_id": "ot1231312",
"out_order_no": "213123",
"refund_total_amount": 100,
"need_refund_audit": 1,
"refund_audit_deadline": 151231321231,
"create_refund_time": 151231321230,
"refund_source": 1,
"refund_reason": ["不喜欢"],
"refund_description": "想退款",
"cp_extra": "cp_extra",
"refund_item_detail": {
"item_order_quantity": 1,
"item_order_detail": [
{
"item_order_id": "ot123134",
"refund_amount": 100
}
]
}
}
{
"app_id": "ttqweqw12312",
"open_id": "123123",
"refund_id": "ot123133",
"order_id": "ot1231312",
"out_order_no": "213123",
"refund_total_amount": 100,
"need_refund_audit": 1,
"refund_audit_deadline": 151231321231,
"create_refund_time": 151231321230,
"refund_source": 1,
"refund_reason": ["不喜欢"],
"refund_description": "想退款",
"cp_extra": "cp_extra"
}
**A: **用户发起、系统自动发起(如过期自动退)、客服发起的退款都会回调开发者。即,所有非开发者通过服务端 openAPI 发起的退款,在成功创建退款单后系统都会回调开发者。
**A: **请按以下步骤排查,
**A: **系统会一直重试,直到成功。未回调成功的退款单会处于卡单状态,会触发系统告警。若对退款有疑问,请咨询行业运营。
**A:**除开发者发起外,还存在用户在退款组件发起、系统自动退款、抖音客服发起等场景,请通过查询退款接口查询订单的退款记录,并检查 refund_source 字段,可以获得具体的退款来源。
若遇到退款单一直处于退款中、审核同步失败的 case,大多数情况是由于没有正确响应退款申请回调导致的。这里提供通用的排查方案,请按步骤执行
curl -X POST '你的退款申请回调地址' -H 'Content-Type:application/json' --data '{
"version": "2.0",
"msg": "",
"type": "pre_create_refund"
}'
如果确认你的回调地址是通的,再进行下一步响应参数检查
a. copy 下面的 python 脚本,保存为 check_your_resp.py
b. copy 你的退款申请回调响应
c. 参考下面这个示例,把响应替换成你自己的,然后执行下面的命令
python check_your_resp.py '{
"err_no":0,
"err_tips":"success",
"data":{
"out_refund_no":"id12348473",
"order_entry_schema":{
"path":"page/refundDetail/xxx",
"params":"{"id":1}"
},
"notify_url":"https://www.abc.com"
}
}'
python 校验脚本
# -- coding: utf-8 --
from jsonschema import validate, draft7_format_checker
from jsonschema.exceptions import SchemaError, ValidationError
import json
import sys
# schema 不要修改!!
schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "test demo",
"description": "validate result information",
"type": "object",
"properties": {
"err_no": {
"description": "error code",
"type": "integer"
},
"err_tips": {
"description": "error msg ",
"type": "string"
},
"data": {
"description": "response date",
"type": "object",
"properties": {
"out_refund_no": {
"type": "string","minLength": 1,"maxLength": 64
},
"notify_url": {
"type": "string",
"pattern":"^|^https://[a-zA-Z0-9\\.\\?/%-_]*","minLength": 0,"maxLength": 512
},
"order_entry_schema": {
"type": "object",
"properties": {
"path": {
"type": "string","minLength": 1,"maxLength": 512
},
"params": {
"type": "string","minLength": 0,"maxLength": 512
}
}
}
},
"required": ["out_refund_no", "order_entry_schema"]
}
},
"required": [
"err_no", "err_tips", "data"
]
}
# 校验方法, 不要修改!!
def check_your_resp(resp):
try:
validate(instance=resp, schema=schema, format_checker=draft7_format_checker)
except SchemaError as e:
print("验证模式schema出错:\n出错位置:{}\n提示信息:{}".format(" --> ".join([i for i in e.path]), e.message))
except ValidationError as e:
print("json数据不符合schema规定:\n出错字段:{}\n提示信息:{}".format(" --> ".join([i for i in e.path]), e.message))
else:
params = resp.get("data",{}).get("order_entry_schema",{}).get("params","")
if len(params) > 0:
try:
obj = json.loads(params)
if type(obj) != dict or len(obj) < 1:
print("data-->order_entry_schema-->params字段必须是序列化后json字符串")
return
except:
print("data-->order_entry_schema-->params字段必须是序列化后json字符串")
return
print("验证成功!")
if name == 'main':
if len(sys.argv)!=2:
print("执行错误, 正确的命令为: python check_your_resp.py your_resp_json")
exit()
try:
resp = json.loads(sys.argv[1])
if type(resp) != dict:
print("执行错误, 输入参数必须是合法的json字符串")
exit()
check_your_resp(resp)
except:
print("执行错误, 输入参数必须是合法的json字符串")
curl --location --request POST 'http://dev-cn.your-api-server.com/api/v2/create_refund?timestamp=1345678901234&nonce=iuy987q4htafreqw' \
--header 'Byte-Authorization: SHA256-RSA2048 appid="ttxxx",nonce_str="DC10180A100073E70A48F195DA2AF2E6",timestamp="1623934869",key_version="1",signature="nwd1L3wCX+01/TVTkILeovF1DtYeghC1VHjrcjTHVkh7+gRaONEQkC2Y72Mw8JdSnIyeAtyp/pDHzyKGywjVqv5+JOBEhQG1/pvwNHN49wD26qg3AJL4hXw0fMJSRiTQEV1MszwDLuaabvo/qM9OXL9KyYiEPwVJqYtzmho4cHXT6mYgzNOW1xt5d7RDf4QO74JI3i4dtk9Uj8svJTrrBabML6AUcqcx2OP/7xukdaUgPdPf+IqmMG6GC4n52LUDogcL5n/osLdfHg9l6kW5gDcDjBfNDaggz07QMPHGdVao7pnQ2ub7VqcFIuY6Q3cBL7ndQdDGKrv+WBy5Q90QjQ=="' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data-raw '{
"version": "2.0",
"msg": "{\"app_id\":\"ttqweqw12312\",\"open_id\":\"123123\",\"refund_id\":\"ot123133\",\"order_id\":\"ot1231312\",\"out_order_no\":\"213123\",\"refund_total_amount\":100,\"need_refund_audit\":1,\"refund_audit_deadline\":151231321231,\"create_refund_time\":151231321230,\"refund_source\":1,\"refund_reason\":[\"不喜欢\"],\"refund_description\":\"想退款\",\"cp_extra\":\"cp_extra\",\"refund_item_detail\":{\"item_order_quantity\":1,\"item_order_detail\":[{\"item_order_id\":\"ot123134\",\"refund_amount\":100}]}}",
"type": "pre_create_refund"
}'{
"err_no": 0,
"err_tips": "123213",
"data": {
"out_refund_no": "89876867867087",
"order_entry_schema": {
"path": "page/refundDetail/xxx",
"params": "{\"id\": 1}"
},
"notify_url": "https://xxx"
}
}