order_test.go 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package sf
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "testing"
  6. )
  7. var (
  8. SF *Client
  9. )
  10. func init() {
  11. SF = NewClient("BZDLLCCSJO4F", "eaUwFnYDoUV2QKgV8j3VxrArDK55PGF7", "", true)
  12. }
  13. //func TestF查询(t *testing.T) {
  14. // id := []string{"SF1697391386502"}
  15. // dd, err := SF.F快递查询(id)
  16. // if err != nil {
  17. // fmt.Println(err.Error())
  18. // return
  19. // }
  20. // fmt.Println(dd)
  21. //
  22. //}
  23. func TestOrder(t *testing.T) {
  24. order := SFOrder{
  25. IsReturnRoutelabel: 1,
  26. CargoDetails: []CargoDetail{
  27. {Name: "苹果手机"},
  28. },
  29. ContactInfoList: []ContactInfo{
  30. {ContactType: ContactTypeSender, Address: "贵州省贵阳市观山湖区金融城C座", Contact: "张三丰", Mobile: "17888888888", Country: "CN"},
  31. {ContactType: ContactTypeConsignee, Address: "贵州省贵阳市观山湖区金融城D座", Contact: "郭襄阳", Mobile: "18963828829", Country: "CN"},
  32. },
  33. Language: "zh-CN",
  34. OrderId: "SF1697391386502",
  35. ExpressTypeId: 1,
  36. PayMethod: 1,
  37. }
  38. //json.Unmarshal([]byte(body), &order)
  39. res, err := SF.Send(EXP_RECE_CREATE_ORDER, &order)
  40. if err != nil {
  41. fmt.Println("err:", err.Error())
  42. return
  43. }
  44. fmt.Println("res:", res)
  45. }
  46. var (
  47. db = `{"apiErrorMsg":"","apiResponseID":"000186644AFEBA3F9365AD375264A03F","apiResultCode":"A1000","apiResultData":"{\"success\":true,\"errorCode\":\"S0000\",\"errorMsg\":null,\"msgData\":{\"orderId\":\"SF192961670303744\",\"originCode\":\"719\",\"destCode\":\"710\",\"filterResult\":2,\"remark\":\"\",\"url\":null,\"paymentLink\":null,\"isUpstairs\":null,\"isSpecialWarehouseService\":null,\"mappingMark\":null,\"agentMailno\":null,\"returnExtraInfoList\":null,\"waybillNoInfoList\":[{\"waybillType\":1,\"waybillNo\":\"SF7444463102821\",\"boxNo\":null,\"length\":null,\"width\":null,\"height\":null,\"weight\":null,\"volume\":null}],\"routeLabelInfo\":[{\"code\":\"1000\",\"routeLabelData\":{\"waybillNo\":\"SF7444463102821\",\"sourceTransferCode\":\"719\",\"sourceCityCode\":\"719\",\"sourceDeptCode\":\"719\",\"sourceTeamCode\":\"\",\"destCityCode\":\"710\",\"destDeptCode\":\"710BF\",\"destDeptCodeMapping\":\"\",\"destTeamCode\":\"001\",\"destTeamCodeMapping\":\"\",\"destTransferCode\":\"710\",\"destRouteLabel\":\"710BF-011\",\"proName\":\"\",\"cargoTypeCode\":\"T6\",\"limitTypeCode\":\"T6\",\"expressTypeCode\":\"B1\",\"codingMapping\":\"S47\",\"codingMappingOut\":\"\",\"xbFlag\":\"0\",\"printFlag\":\"000000000\",\"twoDimensionCode\":\"MMM={'k1':'710','k2':'710BF','k3':'001','k4':'T4','k5':'SF7444463102821','k6':'A','k7':'dd297476'}\",\"proCode\":\"T 标快\",\"printIcon\":\"00010000\",\"abFlag\":\"A\",\"destPortCode\":\"\",\"destCountry\":\"\",\"destPostCode\":\"\",\"goodsValueTotal\":\"\",\"currencySymbol\":\"\",\"cusBatch\":\"\",\"goodsNumber\":\"\",\"errMsg\":\"\",\"checkCode\":\"dd297476\",\"proIcon\":\"\",\"fileIcon\":\"\",\"fbaIcon\":\"\",\"icsmIcon\":\"\",\"destGisDeptCode\":\"710BF\",\"newIcon\":null,\"sendAreaCode\":null,\"destinationStationCode\":null,\"sxLabelDestCode\":null,\"sxDestTransferCode\":null,\"sxCompany\":null,\"newAbFlag\":null,\"destAddrKeyWord\":\"\",\"rongType\":null,\"waybillIconList\":null},\"message\":\"SF7444463102821:\"}],\"contactInfoList\":null,\"sendStartTm\":null,\"customerRights\":null,\"expressTypeId\":null}}"}`
  48. )
  49. func TestF解析(t *testing.T) {
  50. res := new(Response)
  51. if err := json.Unmarshal([]byte(db), res); err != nil {
  52. fmt.Println("err:", err.Error())
  53. return
  54. }
  55. fmt.Println("数据是:", res.ApiResultData)
  56. rdata := new(OrderResponse)
  57. if err := json.Unmarshal([]byte(res.ApiResultData), rdata); err != nil {
  58. fmt.Println("err:", err.Error())
  59. return
  60. }
  61. fmt.Printf("数据是:%+v", rdata)
  62. }