支付宝农产品收购(付款即开票) · 每一单收购
11 查付款和开票状态
没收到通知时主动查这单走到哪一步、钱付了没、票开了没。
地址
POST https://openapi.kailingteck.com/api/v1/alipay-agri/order/query对应支付宝接口:
alipay.commerce.ec.recyclinginvoice.order.query鉴权、外壳、预检(dry_run)、错误码见 调用约定。
请求参数
字段名照支付宝官方文档;中台在你没传时补的值写在「默认」里。不符合官方要求的参数中台直接拦下(CYT_40001),不会发给支付宝。
| 字段 | 类型 | 必填 | 长度 | 说明 |
|---|---|---|---|---|
| tax_no | String | 必填 | 20 | 收购商(企业)统一社会信用代码,18 位 默认:只有开灵在后台为你的凭据登记过企业税号时才能不传;测试凭据默认没登记,请一律传 |
| product_id | String | 必填 | 16 | 农产品收购的发票产品 ID,02 查开通状态返回 默认:不传时:测试环境固定用 2024120022147211;正式环境用开灵为你登记的产品 ID(没登记就必须传) |
| order_id | String | 条件必填 | 28 | 支付宝订单号(下单返回)。也可以只传 outer_order_id,中台按你下单时的单号找回 order_id |
| outer_order_id | String | 条件必填 | 64 | 你的收购单号(下单时传的),与 order_id 二选一 |
| query_options | String | 可选 | 32 | 查询选项(官方必填,中台可代填),BIZ_TRANSFER 时多返回业务转账信息 默认:BIZ_TRANSFER |
返回 data
支付宝返回的业务字段原样保留;中台另补的字段已注明。
order_status:WAIT_LINK 待关联 / WAIT_AUDIT 待审核 / WAIT_CONFIRM 待农户确认 / CONFIRMED 已确认 / WAIT_PAY 待支付 / SUCCESS 交易成功 / CANCEL 已取消 / FAILED 失败 / WAIT_DEPOSIT 待入账order_payment:pay_status(PAY_SUCCESS / PAY_CANCELED)、pay_amount、pay_status_message(失败原因,如农户未实名)order_invoice_list[]:发票:invoice_type(BLUE / RED)、invoice_status、invoice_status_message(开票失败原因)、invoice_no、invoice_date、pdf_file_url、img_file_url、金额税额、明细order_amount / tax_total_amount / gmt_success:订单金额、缴税总额(农产品免税一般为 0)、成功时间summary:中台补,放在 data 最前面。outcome 是你的系统该落的结果:success 已付款已开票 / reversed 已冲红 / pay_failed 转账失败(农户处理后 15 重试)/ invoice_failed 已付款开票失败(15 重试)/ cancelled 已撤单 / failed 失败 / pending 处理中(继续等);另有 text 一句话(给人看)、paid、invoiced、blue_invoice_no、blue_invoice_status、red_invoice_status、pay_message、invoice_message;final=outcome 不是 pending(表示这一轮可以停止轮询,失败的单重试后要再接着查),以 outcome 为准
常见错误与处理
支付宝业务失败时外壳是 CYT_42200,data.upstreamCode 是支付宝错误码。
ORDER_NOT_EXIST:订单号不对COMPANY_PRODUCT_NOT_EXIST:product_id 不对(用 02 返回的农产品收购产品 ID)CACULATE_TAX_ERROR:支付宝实时计税异常,稍后重试
注意
- 轮询建议 15 秒一次,按 summary.outcome 落结果:pending 继续等,其余都停(pay_failed、invoice_failed 处理后调 15 重试再接着查)。
- 不要用 summary.text 判断状态,它只是给人看的一句话。
实测示例
脚本 11_order_query.py(Python 3.6+ 标准库,公共模块 kl_agri.py)。以下运行记录是测试环境实跑的请求和返回,个人信息已脱敏。
#!/usr/bin/env python3
"""11 查付款和开票状态。
用法:python3 11_order_query.py [order_id]"""
import sys
from kl_agri import *
body = {"tax_no": TAX_NO, "order_id": arg(1, "KL_ORDER_ID", "order_id")}
resp, ok_ = run("11_order_query", "order/query", body)
if ok_:
print("summary =", json.dumps(resp["data"]["summary"], ensure_ascii=False))
11_order_query · 2026-10-25 · HTTP 200 · 通过
请求体
{
"tax_no": "91110108MA01AGRP8X",
"order_id": "2026102629783220338950807601"
}返回
{
"code": "CYT_00000",
"msg": "success",
"data": {
"summary": {
"outcome": "success",
"text": "已付款·已开票",
"paid": true,
"invoiced": true,
"blue_invoice_no": "26333842846494017587",
"blue_invoice_status": "INVOICE_SUCCESS",
"red_invoice_status": "",
"final": true
},
"outer_order_id": "KLAGRIPO26102512240651483",
"order_id": "2026102629783220338950807601",
"tax_no": "91110108MA01AGRP8X",
"product_id": "2024120022147211",
"company_clerk_id": "2026102681845578",
"company_supplier_id": "2026102655781135967218174991",
"seller_name": "测***",
"order_amount": "80.00",
"order_status": "SUCCESS",
"gmt_success": "2026-10-26 00:24:06",
"order_invoice_list": [
{
"invoice_no": "26333842846494017587",
"invoice_type": "BLUE",
"invoice_status": "INVOICE_SUCCESS",
"invoice_kind": "ORDINARY_INVOICE",
"invoice_amount": "80.00",
"invoice_amount_without_tax": "80.00",
"invoice_tax_amount": "0.00",
"invoice_date": "2026-10-26 00:24:06",
"pdf_file_url": "https://openapi.kailingteck.com/samples/alipay-agri/sandbox-invoice.pdf",
"img_file_url": "https://openapi.kailingteck.com/samples/alipay-agri/sandbox-invoice.pdf",
"buyer_tax_no": "91110108MA01AGRP8X",
"seller_name": "测***",
"clerk": "测试开票员",
"order_invoice_item_list": [
{
"serial_no": "1",
"item_name": "大白菜",
"item_unit": "公斤",
"item_num": "100",
"item_tax_rate": "0",
"item_total_amount": "80.00",
"item_amount": "80.00",
"item_tax_amount": "0.00",
"item_unit_amount": "0.80",
"item_tax_code": "1010112040000000000",
"item_category_name": "模拟",
"invoice_line_property": "NORMAL_LINE",
"favoured_policy_flag": "TAX_EXEMPT"
}
]
}
],
"tax_total_amount": "0.00",
"order_tax_item_list": [],
"order_item_list": [
{
"order_item_id": "2026102629783220338950800001",
"item_name": "大白菜",
"item_category_name": "模拟",
"tax_code": "1010112040000000000",
"item_unit_amount": "0.80",
"item_num": "100",
"item_total_amount": "80.00",
"item_unit": "公斤"
}
],
"order_payment": {
"pay_no": "2026344638096858173851632430",
"pay_status": "PAY_SUCCESS",
"company_account_id": "sbx-account",
"pay_amount": "80.00"
},
"biz_transfer_list": [],
"memo": "农产品收购",
"payment_invoice_page_url": "https://openapi.kailingteck.com/docs/alipay-agri/sandbox-simulate#clerk-page-2026102629783220338950807601",
"payment_invoice_page_alipay_url": "alipays://platformapi/startapp?appId=2021004158631382&role=OPERATOR&sandbox=2026102629783220338950807601",
"collection_invoice_page_url": "https://openapi.kailingteck.com/docs/alipay-agri/sandbox-simulate#farmer-page-2026102629783220338950807601",
"collection_invoice_page_alipay_url": "alipays://platformapi/startapp?appId=2021004158631382&role=SELLER&sandbox=2026102629783220338950807601",
"env": "sandbox"
}
}11_order_query--before-audit(异常分支) · 2026-10-25 · HTTP 200 · 通过
请求体
{
"tax_no": "91110108MA01AGRP8X",
"order_id": "2026102619941073854692987061"
}返回
{
"code": "CYT_00000",
"msg": "success",
"data": {
"summary": {
"outcome": "pending",
"text": "待企业审核(调 13)",
"paid": false,
"invoiced": false,
"blue_invoice_no": "",
"blue_invoice_status": "",
"red_invoice_status": "",
"final": false
},
"outer_order_id": "KLAGRIPO26102512240732129",
"order_id": "2026102619941073854692987061",
"tax_no": "91110108MA01AGRP8X",
"product_id": "2024120022147211",
"company_clerk_id": "2026102681845578",
"company_supplier_id": "2026102655781135967218174991",
"seller_name": "测***",
"order_amount": "80.00",
"order_status": "WAIT_AUDIT",
"order_invoice_list": [],
"tax_total_amount": "0.00",
"order_tax_item_list": [],
"order_item_list": [
{
"order_item_id": "2026102619941073854692980001",
"item_name": "大白菜",
"item_category_name": "模拟",
"tax_code": "1010112040000000000",
"item_unit_amount": "0.80",
"item_num": "100",
"item_total_amount": "80.00",
"item_unit": "公斤"
}
],
"order_payment": {},
"biz_transfer_list": [],
"memo": "农产品收购",
"payment_invoice_page_url": "https://openapi.kailingteck.com/docs/alipay-agri/sandbox-simulate#clerk-page-2026102619941073854692987061",
"payment_invoice_page_alipay_url": "alipays://platformapi/startapp?appId=2021004158631382&role=OPERATOR&sandbox=2026102619941073854692987061",
"collection_invoice_page_url": "https://openapi.kailingteck.com/docs/alipay-agri/sandbox-simulate#farmer-page-2026102619941073854692987061",
"collection_invoice_page_alipay_url": "alipays://platformapi/startapp?appId=2021004158631382&role=SELLER&sandbox=2026102619941073854692987061",
"env": "sandbox"
}
}