從事電商軟體開發的小夥伴,在日常開發任務中,經常會遇到一個需求,就是將淘寶店鋪的訂單,同步到自己的內部訂單管理系統OMS中,進行淘寶打單發貨操作。我介紹下如何將訂單同步下來,供各位參考。(注意:所有電商平臺目前能同步訂單的介面要麼就不讓申請,要麼就申請門檻和維護資質的成本很高,具體有需要的小夥伴可以評論區留言,我會告訴你相關平臺是否可以申請以及申請規則等)
訂單列表同步,一共有三個方案。
第一種方案:對於訂單量比較大的使用者(系統日訂單幾十萬上百萬的那種),當仁不讓的就是聚石塔RDS同步。
這種方案的好處是,只需要透過對淘寶開放平臺後端應用進行相關的配置,淘寶就會自動將訂單資料,推送到你配置的RDS資料庫中,非常簡單,同步速度也很快。壞處在於一定是要聚石塔的RDS,不支援資料庫欄位對映,相當於同步過來後你需要進行資料遍歷處理,處理完了以後重新儲存到一個新的表裡面去,因為你的業務的相關欄位,不可能和淘寶一模一樣的,只有設定一個作業執行緒,定時輪詢表資料,將表資料處理翻譯欄位後,再存到新的表裡面。
資料同步設定路徑為:開啟淘寶開放平臺->開發->同步設定-選擇對應應用->同步設定,在這裡就可以設定同步哪些欄位,哪些訂單,哪些商家了。(也可以透過API來設定同步哪些商家)
第二種方案:對於訂單量少一些的,可以採用TMC訊息方案。
TMC訊息方案,簡單來說就是當訂單建立、訂單支付、訂單退款等事件發生後,淘寶會給我們推送一條類似RocketMQ訊息,我們透過設定客戶端消費訊息,來達到實時知道訂單的變化情況,然後透過獲取訊息體中的關鍵欄位或者透過關鍵欄位呼叫相關API介面來獲取訂單相關欄位來達到同步的效果。說起來是不是有點繞口了,舉個例子來說吧。
比如我們可以監聽 taobao_trade_TradeCreate 這個TOPIC,當買家下單後,淘寶會給我們推送這個TOPIC的訊息,推送內容如下:
{ "buyer_nick":"碎**", "buyer_open_uid":"AAGq5d-EAAeG3JedwSFpZMe1", "payment":"100.00", "oid":"987654321", "seller_nick":"麥包包", "type":"fixed", "tid":"123456789", "status":"TRADE_CREATE" }
剛剛這個JSON,只是官方的一個示例JSON,實際上的話欄位可能比這多點,以實際欄位為準。我們可以看到其中有幾個關鍵欄位,比如說tid,就是淘寶訂單號,假設我們需要知道訂單詳細購買了哪些商品,我們就可以透過tid,來呼叫淘寶訂單資訊獲取介面API來獲取淘寶訂單資訊,其對應的TOP介面為 taobao.trade.fullinfo.get ,透過這個介面,就可以獲取非常詳細的淘寶訂單資訊,這個介面的入參如下:
可以看到必填引數中,一個是需要獲取的欄位,一個是淘寶訂單號,需要獲取的欄位是必填的,只有填了欄位名的,淘寶才會返回,沒填寫的淘寶不會返回。
該介面的返回內容如下:
{"trade_fullinfo_get_response":{"trade":{"buyer_open_uid":"AAHk5d-EAAeGwJedwSFu0XXX","title":"麥包包","type":"fixed(一口價)","created":"2000-01-01 00:00:00","sid":"2231958349","tid":2231958349,"acookie_id":"1a11a0987628772c002ec7d0eec2a352","seller_rate":true,"buyer_rate":true,"status":"TRADE_NO_CREATE_PAY","payment":"200.07","discount_fee":"200.07","adjust_fee":"200.07","post_fee":"200.07","total_fee":"200.07","pay_time":"2000-01-01 00:00:00","end_time":"2000-01-01 00:00:00","modified":"2000-01-01 00:00:00","consign_time":"2000-01-01 00:00:00","received_payment":"200.07","commission_fee":"200.07","buyer_memo":"上衣要大一號","seller_memo":"好的","buyer_area":"浙江省杭州市","alipay_no":"2009112081173831","buyer_message":"要送的禮物的,不要忘記的哦","pic_path":"http:\/\/img08.taobao.net\/bao\/uploaded\/i8\/T1jVXXXePbXXaoPB6a_091917.jpg","num_iid":3424234,"price":"200.07","cod_fee":"12.07","cod_status":"EW_CREATED(訂單已建立)","buyer_cod_fee":"12.07","seller_cod_fee":"12.07","express_agency_fee":"212.07","shipping_type":"free","num":1,"point_fee":0,"real_point_fee":0,"buyer_obtain_point_fee":0,"buyer_alipay_no":"tbtest1063@taobaotest.com","receiver_name":"**東方","receiver_country":"中國","receiver_state":"浙江省","receiver_city":"杭州市","receiver_district":"西湖區","receiver_town":"三墎鎮","receiver_address":"***淘寶城911號","receiver_zip":"223700","receiver_mobile":"****1826","receiver_phone":"****5372","buyer_email":"tbtest1064@taobaotest.com","seller_alipay_no":"tbtest1063@taobaotest.com","seller_mobile":"13512501826","seller_phone":"13512501826","seller_name":"我在測試","seller_email":"tbtest1063@taobaotest.com","available_confirm_fee":"200.07","has_post_fee":true,"timeout_action_time":"2000-01-01 00:00:00","snapshot_url":"T1mURbXopZXXXe3rLI.1257513712679_snap","trade_memo":"這是一次成功的交易","promotion":"hello world","is_3D":true,"is_lgtype":true,"is_brand_sale":true,"is_force_wlb":true,"buyer_flag":1,"seller_flag":1,"credit_card_fee":"30.5","step_trade_status":"FRONT_NOPAID_FINAL_NOPAID","step_paid_fee":"525.70","eticket_ext":"525.70","mark_desc":"該訂單需要延長收貨時間","has_yfx":true,"yfx_fee":"0.50","yfx_id":"135751716473138","yfx_type":"taojinbi","send_time":"2000-01-01","can_rate":true,"seller_can_rate":true,"is_part_consign":true,"is_daixiao":true,"is_wt":true,"arrive_interval":1,"arrive_cut_time":"16:00","consign_interval":48,"o2o":"crm","o2o_guide_id":"123456","o2o_guide_name":"西湖門店導購員1","o2o_shop_id":"123456","o2o_shop_name":"西湖門店","o2o_delivery":"inshop","o2o_out_trade_id":"123456","shop_code":"demo","hk_en_name":"chenxiao","hk_flight_no":"GZ0022","hk_china_name":"陳小","hk_card_code":"G0000000001","hk_card_type":"證件型別","hk_flight_date":"2014-12-01 15:50","hk_gender":"M","hk_birthday":"1988-01-12","hk_pickup":"某地點","hk_pickup_id":"3","est_con_time":"付款後30天內","orders":{"order":[{"title":"山寨版測試機器","pic_path":"http:\/\/img08.taobao.net\/bao\/uploaded\/i8\/T1jVXXXePbXXaoPB6a_091917.jpg","price":"200.07","num_iid":2342344,"sku_id":"5937146","outer_iid":"152e442aefe88dd41cb0879232c0dcb0","outer_sku_id":"81893848","refund_status":"SUCCESS(退款成功)","status":"TRADE_NO_CREATE_PAY","oid":2231958349,"total_fee":"200.07","payment":"200.07","discount_fee":"200.07","adjust_fee":"1.01","divide_order_fee":"21.00","part_mjz_discount":"21.00","sku_properties_name":"顏色:桔色;尺碼:M","item_meal_id":2564854632,"item_meal_name":"M8原裝電池:便攜支架:M8專用座充:莫凡保護袋","num":1,"snapshot_url":"T1mURbXopZXXXe3rLI.1257513712679_snap","timeout_action_time":"2000-01-01 00:00:00","item_memo":"這是商品備註","buyer_rate":true,"seller_rate":true,"refund_id":"2231958349","seller_type":"B(商城商家)","cid":123456,"is_oversold":true,"end_time":"2012-04-07 00:00:00","order_from":"jhs","is_service_order":true,"consign_time":"2013-01-13 15:23:00","shipping_type":"post","logistics_company":"順風快遞","invoice_no":"05432465","bind_oid":23194074143138,"is_daixiao":true,"ticket_outer_id":"123456abcd","ticket_expdate_key":"100FFFFFF02374020000002001020304000A","is_www":true,"store_code":"南京QDHEWL-0004","tmser_spu_code":"裝潢干支裝服務","sub_order_tax_fee":"0","sub_order_tax_rate":"0","et_ser_time":"2015-04-15 13:00","et_shop_name":"測試預約門店地址","et_verified_shop_name":"測試核銷門店地址","et_plate_number":"浙A11111","estimate_con_time":"demo","bind_oids":"193741211090019,193741211080019","zhengji_status":"1","md_qualification":"true_免單原因","md_fee":"999","customization":"{ "itemId": 123, "skuId": 123, "text": [ { "id": 44, "content": "home" } ], "pic": [ { "id": 44, "url": "sn" } ] ,"dingzhi":";pluginId:182;dingzhiId:157886;"}","inv_type":"6","is_sh_ship":true,"shipper":"cn","f_type":"jsd","f_status":"分單完成","f_term":"storeId","combo_id":"1923423423","order_attr":"{"isFreeDownPayment":"true","backPayment":"3000.00","refActivityId":"312321312"}","assembly_rela":"123123","assembly_price":"123123123","assembly_item":"123,456","sub_order_tax_promotion_fee":"0","down_payment":"1000","down_payment_ratio":"1000","month_payment":"1000","tail_payment":"1000","installment_num":"1000","penalty":"1000","service_fee":"1000","car_taker":"1000","car_taker_phone":"1000","car_taker_id":"1000","car_store_code":"1000","car_store_name":"1000","out_unique_id":"1000","ws_bank_apply_no":"1000","oid_str":"123","fqg_num":12,"is_fqg_s_fee":true,"tax_free":true,"tax_coupon_discount":"0","nr_reduce_inv_fail":"1","nr_outer_iid":"2983778187","bind_oids_all_status":"193741211090019,193741211080019","sort_info":{"day_sort_val":100,"hour_sort_val":100},"o2o_guide_id":"12345","o2o_guide_name":"abc","o2o_shop_id":"12345","o2o_shop_name":"abc","biz_code":"tmall.daogoubao.cloudstore","cloud_store":"1","hj_settle_no_commission":"1","order_taking":"接單標記","cloud_store_token":"11111","cloud_store_bind_pos":"12345","retail_store_id":"123415","out_item_id":"12345","rt_omni_outer_sc_id":"12345","rt_omni_sc_id":"12345","modify_address":"1","ti_modify_address_time":"2019-02-18 11:32:53","credit_buy":"3","s_tariff_fee":"0","timing_promise":"tmallPromise","promise_service":"tmallpromise.arrival.timing,tmallpromise.xx.timing","es_date":"格式yyyy-MM-dd","es_range":"格式 hh:mm-hh:mm","os_date":"格式yyyy-MM-dd","os_range":"格式 hh:mm-hh:mm","cutoff_minutes":"660","es_time":"1","delivery_time":"2019-04-12 16:00:00","collect_time":"2019-04-12 16:00:00","dispatch_time":"2019-04-12 16:00:00","sign_time":"2019-04-12 16:00:00","promise_end_time":"格式yyyy-MM-dd HH:mm","os_activity_id":"2734957495","os_fg_item_id":"58901376862","os_gift_count":"1","os_sort_num":"10","propoint":"10","is_kaola":true,"special_refund_type":"2","extend_info":"{"itemTag":"100"}","is_devalue_fee":true,"brand_light_shop_store_id":"123456","brand_light_shop_source":"scode","service_order_type":"1","service_outer_id":"sunin_outid_324324324","expand_card_expand_price_used_suborder":"10.01","expand_card_basic_price_used_suborder":"10.01","lijian":"10.01","auto_flow":"0\/1","trade_fulfillment_type":1/2/3/4,"distribute_status":"distribute","is_idle":"1","gift_mids":"22331764490705","is_free_gift":true,"has_gift":true,"promise_collect_time":"2019-04-12 16:00:00","is_force_dc":true,"b2b_daixiao":"1","ship_info":{"ship_info":[{"transport_type":"express,seller,instant等"}]},"combine_item_info":{"combine_sub_item_d_o":[{"item_id":123123,"sku_id":22331764490705,"quantity":數量,"item_name":"商品名稱","outer_iid":"152e442aefe88dd41cb0879232c0dcb0","sku_title":"16g","origin_fee":123,"combine_sub_item_fee":123,"ismain":true,"estcon_time":"7 \/ 2023-02-15","outer_sku_id":"123","edu_original_fee":123}]},"need_return":true,"bundle_id":"123","bundle_out_name":"Apple","bundle_type":1,"one_yuan_reservation_orders":"3330286058340981615,3330286058340981614","is_jzfx":true,"jewcc_no":"TBJA34876579730796583190"}]},"promotion_details":{"promotion_detail":[{"id":22331764490705,"promotion_name":"滿就減錢","discount_fee":"10.00","gift_item_name":"晨光簽字筆","gift_item_id":"13233791195","gift_item_num":"1","promotion_desc":"雙11促銷,滿就送","promotion_id":"mjs","kd_discount_fee":"10.00","kd_child_discount_fee":"22331764490703|5.00,22331764490704|5.00"}]},"service_tags":{"logistics_tag":[{"order_id":"123456","logistic_service_tag_list":{"logistic_service_tag":[{"service_tag":"comFee=1211;comTim=1;companyCode=SF;","service_type":"FAST"}]}}]},"service_orders":{"service_order":[{"oid":110770592823138,"item_oid":110770592803138,"service_id":2342344,"service_detail_url":"http:\/\/wt.taobao.com\/plan.htm?plan_id=planId","num":1,"price":"39.09","payment":"29.98","title":"滾筒洗衣機","total_fee":"39.09","buyer_nick":"小倩2005","refund_id":"2231958349","seller_nick":"麥包包","pic_path":"http:\/\/img08.taobao.com\/bao\/upload\/i8\/T1jVXXXePb_a0908.jpg","tmser_spu_code":"裝潢干支裝服務","et_ser_time":"2015-04-15 13:00","et_shop_name":"測試預約門店地址","et_verified_shop_name":"測試核銷門店地址","et_plate_number":"浙A11111","oid_str":"110770592823138","apple_care_email":"1","apple_care_mpn":"1","service_outer_id":"suni_outid_23432","service_order_type":"1","ext_service_biz_id":"23423_324234,2324_342342","combine_sub_item_id":123,"combine_sub_item_sku_id":123,"comm_amount_unit":"123"}]},"trade_from":"WAP,JHS","trade_source":"ownshop","zero_purchase":true,"alipay_point":1,"pcc_af":1,"trade_ext":{"before_enable_flag":1,"before_close_flag":1,"before_pay_flag":1,"before_ship_flag":1,"before_confirm_flag":1,"before_rate_flag":1,"before_refund_flag":1,"before_modify_flag":1,"third_party_status":1,"extra_data":"abc","ext_attributes":"abc"},"order_tax_fee":"0","et_ser_time":"2015-04-15 13:00","et_shop_name":"介面測試新增門店_0304055043555","et_verified_shop_name":"測試核銷門店地址","et_plate_number":"浙A11111","o2o_snatch_status":"1","is_sh_ship":true,"eticket_service_addr":"地址資訊","et_type":"bs_common","market":"eticket","obs":"1","et_shop_id":66749068,"paid_coupon_fee":"10.00","shop_pick":"1","rx_audit_status":"0","es_date":"直接下單預計時間","es_range":"直接下單預計時間","os_date":"預約下單時間","os_range":"預約下單時間","coupon_fee":使用紅包付款金額,"post_gate_declare":true,"cross_bonded_declare":true,"trade_attr":"{\"payCurrency\":\"HKD\"}","top_hold":0,"omni_attr":"{}","omni_param":"{}","assembly":"1","forbid_consign":1,"identity":"EPP","team_buy_hold":1,"share_group_hold":1,"ofp_hold":1,"o2o_step_trade_detail":"3_1_100_paid","o2o_step_order_id":"2505550397798727","o2o_et_order_id":"2505550397798727","o2o_voucher_price":"1000","order_tax_promotion_fee":"0","delay_create_delivery":1,"tid_str":"123","toptype":1,"service_type":"timedd,jiaju","o2o_service_mobile":"17802118895","o2o_service_name":"衍一","o2o_service_state":"浙江省","o2o_service_city":"杭州市","o2o_service_district":"餘杭區","o2o_service_town":"五常街道","o2o_service_address":"杭州市餘杭區文一西路969號","o2o_step_trade_detail_new":"bizType:分階段付款交易,orderPayChannel:支付寶線上支付,subOrderPayTime:step 0: payTime Sun Jul 30 17:08:50 CST 2017 step 1: payTime Sat Aug 05 04:07:14 CST 2017 ,totalStep:2,currStep:2,fee:60300,payStatus:paid","o2o_xiaopiao":"123","o2o_contract":"3213","recharge_fee":"100","retail_store_code":"123","retail_out_order_id":"123","platform_subsidy_fee":"100.00","nr_offline":"1","wtt_param":"json格式","logistics_infos":{"logistics_info":[{"trade_id":1100070860172581613,"sub_trade_id":1100070860173581613,"item_id":"2323232","item_code":"323232","need_consign_num":5,"store_code":"2223","type":"00","sku_id":"213","num_iid":12222,"consign_type":"cn","combine_item_id":"1231234","combine_item_code":"13123","item_ratio":1,"bar_code":"691234","delivery_cps":"STO","biz_delivery_code":"e_delivery_code","biz_store_code":"e_store_code","biz_sd_type":"0","send_country":"中國","send_state":"浙江省","send_city":"杭州市","send_district":"西湖區","send_town":"三墎鎮","send_division_code":"330110005","black_delivery_cps":"STO,SF","white_delivery_cps":"STO,SF","biz_delivery_type":1,"unused_warehouse_error_msg":"當前訂單在貓淘平臺對消費者進行了服務承諾:當日發次日達,建議按照平臺要求進行擇倉,否則存在賠付風險。","unused_delivery_error_msg":"當前訂單在貓淘平臺對消費者進行了服務承諾,建議按照平臺要求進行擇配,否則存在賠付風險”\/“平臺建議當前線路您只能選擇的配品牌,存在電子面單無法列印風險","used_black_delivery_error_msg":"平臺建議當前線路不要使用您選擇的配品牌,存在電子面單無法列印風險","promise_outbound_time":"2019-04-12 16:00:00","promise_collect_time":"2019-04-12 16:00:00"}]},"seller_nick":"我在測試","buyer_nick":"我在測試","nr_store_order_id":"下發鮮生活訂單號","nr_shop_id":"1","nr_shop_name":"1","nr_shop_guide_id":"1","nr_shop_guide_name":"1","sort_info":{"day_sort_val":100,"hour_sort_val":100},"sorted":1,"nr_no_handle":"1","biz_code":"tmall.daogoubao.cloudstore","cloud_store":"1","is_gift":暫不公開,"donee_nick":"暫不公開","donee_open_uid":"暫不公開","suning_shop_code":"123","suning_shop_valid":1,"allow_appkeys":"123,456","new_presell":true,"you_xiang":true,"retail_store_id":"1","is_istore":ture,"ua":"ap","linkedmall_ext_info":"{}","pay_channel":"0","rt_omni_send_type":"pickUp","rt_omni_store_id":"12345","rt_omni_outer_store_id":"12345","tcps_start":"2018-10-10 11:00:00","tcps_code":"com.tmall.dsd","tcps_end":"2018-10-10 13:00:00","m_tariff_fee":"0","timing_promise":"tmallPromise","promise_service":"aa,bb,cc","cutoff_minutes":"660","es_time":"1","delivery_time":"2019-04-12 16:00:00","collect_time":"2019-04-12 16:00:00","dispatch_time":"2019-04-12 16:00:00","sign_time":"2019-04-12 16:00:00","outer_partner_member_id":"123456","root_cat":"1234567","gifting":"1","gifting_takeout":"1","oi_date":"8:00-9:00","oi_range":"2019-08-01","hold_install":"暫不安裝","app_name":"tmall","easy_home_city_type":"deposit:預約,tail:尾款,direct:直接購買","nr_deposit_order_id":"123456","nr_store_code":"123456","propoint":"10","zqs_order_tag":"1","txp_freezer_id":"1234","txp_receive_method":"post","expandcard_info":{"basic_price":"0.01","expand_price":"0.01","basic_price_used":"0.01","expand_price_used":"0.01"},"extend_info":"{"itemTag":"100"}","lm":"1","brand_light_shop_source":"scode","brand_light_shop_store_id":"123456","is_wmly":"1","omni_package":"[{"city_token":"155774003320052624","pickup_code":"059006","latest_prepare_time":"2020-05-26 13:00:00","select_time":"2020-05-26 13:00-17:00","sub_order_ids":"1234,2345"}]","ncz_ext_attr":"{}","invoice_detail_pay":"{"result":{"$ref":"@"},"1100453005045981418":[{"details":[{"amount":0.50,"name":"信用購"}],"type":"消費積分"}],"success":true,"errorCode":""}","invoice_detail_mid_refund":"{"result":{"$ref":"@"},"1100453005045981418":[{"details":[{"amount":0.50,"name":"信用購"}],"type":"消費積分"}],"success":true,"errorCode":""}","invoice_detail_after_refund":"{"result":{"$ref":"@"},"1100453005045981418":[{"details":[{"amount":0.50,"name":"信用購"}],"type":"消費積分"}],"success":true,"errorCode":""}","expand_card_basic_price":"0.01","expand_card_expand_price":"0.01","expand_card_basic_price_used":"0.01","expand_card_expand_price_used":"0.01","delivery_cps":"SF","asdp_biz_type":"logistics_upgrade","is_openmall":false,"v_logistics_create":false,"q_r_pay":false,"order_follow_id":"1","asdp_ads":"201","ob_tag":"lg","general_new_presell":true,"drug_register":"1","step_pay_details":{"step_pay_detail":[{"id":1,"pay_status":2,"step_no":1,"step_channel_no":"2021111222001188701414727247","step_instrument_code":"ALIPAY_BATCH_ESCROW_APP","step_actual_pay_fee":"10.00"}]},"agree_refund_checks":{"agree_refund_check":[{"delivery_tips":"demo","delivery_process":"demo","detail_order_id":"demo"}]},"address_details":{"address_detail":[{"detailed_address":"demo","division_code":"demo","area":"demo","telephone":"demo","city":"demo","prov":"demo","country":"demo","contact_name":"demo","biz_type":"demo"}]},"stage_address_type":"identifyService","og_id":"3628641205792","promise_sign_time":"1","tmall_coupon_fee":100,"delivery_plan":{"delivery_plan":[{"plan_id":100,"order_id":100,"curr_phase":100,"out_logistics_id":"demo","prepare_time_begin":"2015-01-01 00:00:00","ship_time_begin":"2015-01-01 00:00:00","actual_ship_time":"2015-01-01 00:00:00","goods_num":100,"plan_status":100,"plan_refund_status":100,"receiver_name":"1","receiver_mobile":"1","receiver_phone":"1","receiver_address":"1","oaid":"demo","privacy_num":"demo","privacy_expire_time":"time","receiver_town":"1","receiver_district":"1","receiver_city":"1","receiver_state":"1","receiver_country":"1"}]},"omnichannel_param":"orderState:X_SHOP_HANDLED,orderType:STORE_DELIVER,acceptExpirationTime:2016-09-05 23:41:59,targetCode:34510274,allocationCode:339001,subOrderCode:194497830335000,targetType:STORE;","oaid":"2w2RYE45iahnF4aiaJ7pHKCJ3Hwnbgnq2PH3AfpQVyWZNHKS9wNgAAOUfCVt9XZMetogNHwc","is_cycle_buy":true,"scenario_group":"TXD_B2C_FRESH_HALFDAY","play_type":"group_buy","is_force_dc":true,"combine_logistics_details":{"combine_logistics_detail":[{"invoice_no":"123123123","logistics_company":"xx物流公司","sub_order_id":"123123123","send_goods_details":{"send_goods_detail":[{"type":1,"consign_status":1,"amount":3,"goods_details":{"package_goods_detail":[{"item_id":123123,"sku_id":123123,"amount":123}]}}]}}]},"identify_info":{"identify_logistics_infos":{"identify_logistics_info":[{"detail_order_id":123123,"logistics_company":"xx物流公司","stage_no":2,"invoice_no":"123123","refund_id":"123123","refund":false}]},"identify_service_infos":{"identify_service_info":[{"detail_order_id":123123,"unit_id":"123123","service_id":"123123"}]}},"logistics_consign_info":{"logistics_consign_info":[{"related_id":"1234567","consign_time":"付款後30天內","render_consign_time":"付款後30天內","combine_item":{"combine_consign_info":[{"comb_id":"56789","item_id":"23456789","sku_id":"678998","consign_time":"付款後30天內","render_consign_time":"付款後30天內"}]}}]},"logistics_modify_info":{"logistics_modify_info":[{"related_id":"1234567","consign_time":"付款後30天內","origin_consign_time":"付款後32天內","modify_time":"2023-04-01 11:11:11","modify_reason":"提前發貨時效","item_id":"124556","sku_id":"56789","comb_id":"567890"}]},"priority_consign_time":"2023-04-26 03:26","logistics_agreement":{"logistics_service_msg":"送貨上門","asdp_biz_type":"logistics_upgrade","asdp_ads":"201","sign_time":"2019-04-12 16:00:00","promise_sign_time":"2019-04-12 16:00:00","push_time":"2019-04-12 16:00:00"},"real_name_auth_status":"0","third_party_customs_declaration":"0","receipt_type":"ITEM"}}}
透過該json大家可以瞭解淘寶會返回哪些欄位。我們這只是訂閱了一個TOPIC的訊息,還有其他TOPIC的,比如說買家付款、買家退款等,任何一個TOPIC的訊息,裡面都有核心的欄位,比如淘寶訂單號、退款金額、付款金額等,如果欄位不夠用,我們就可以考慮呼叫相關的介面。比如如果退款訊息只有退款編號,我們就可以透過退款編號,呼叫淘寶退款資訊查詢介面進行查詢,查詢拿到結果後,再寫入自己的資料庫。
該方案的好處在於訊息非常及時,呼叫起來也簡單。而且訊息通知是免費的(注意:呼叫介面不一定免費),當免費的訊息通知中含有你需要的欄位,相當於你就是完全免費同步了。
第三種方案一般是不被推薦的,但是適合那種比較訂單量小的,要求開發簡單的,但是也是最為可靠穩定的(訊息方案對於消費客戶端的處理還是有點需要經驗的,雖然有客戶端,難度也算有點),這個方案就是定時查詢增量訂單列表介面
淘寶提供了增量訂單列表查詢介面taobao.trades.sold.increment.get,該介面允許使用者查詢某段時間內的增量訂單,所以使用者只需要設定一個作業執行緒,定時呼叫這個介面即可,訂單同步的時間及時與否,取決於定時多久,比如說5秒查詢一次,遍歷介面的好處在於,開發起來很簡單,並且穩定性極高,但是對於訂單量大的使用者來說不太合適,只適合一天幾百幾千上萬單的系統,太多的訂單的話,請求次數多,且無法做到非常及時。請求次數多流量費就高。
這個介面的入參如下:
返回結果太長了,參考上面那個淘寶訂單詳情獲取介面的結果即可(有些欄位可能沒有,列表獲取的欄位沒有詳情介面那麼齊全,但是大部分都有的,如果沒有的話,就只能去呼叫淘寶訂單資訊獲取介面API來查詢詳細訂單資訊)
三種方案都說完了,總結一下:
如果你的系統日處理訂單達到幾十萬上百萬的規模的,建議採用方案1的聚石塔RDS同步方案。
如果你的系統日處理訂單隻有幾萬或者十幾萬的規模的,建議採用方案2的淘寶TMC訊息方案來獲取淘寶訂單資訊同步到你的資料庫。
如果你的系統日處理訂單隻有幾百幾千或者幾萬的規模,建議採用方案3的定時呼叫淘寶增量訂單列表獲取介面的方案,這個方案寫程式碼很簡單,並且非常穩定可靠,也無需額外一些配合和配置,具體哪種方案就小夥伴們自己選擇了