229 lines
13 KiB
Go
229 lines
13 KiB
Go
package uuptapi
|
||
|
||
import (
|
||
"git.rosy.net.cn/baseapi/platformapi"
|
||
"net/http"
|
||
"sync"
|
||
)
|
||
|
||
const (
|
||
//正式环境
|
||
TokenURL = "https://openapi.uupt.com/v2_0/"
|
||
//沙箱环境
|
||
//TokenURL = "http://openapi.test.uupt.com/v2_0/"
|
||
RequestPost = "POST"
|
||
WaybillCallbackURL = "http://callback.jxc4.com/UuPt/UuWaybillCallback"
|
||
)
|
||
const (
|
||
CancelReasonNormal = "其他"
|
||
|
||
//运单状态
|
||
StateConfirmSuccess = "1" //下单成功
|
||
StateRMGrabsOrder = "3" //跑男抢单
|
||
StateArrivedStore = "4" //已到达
|
||
StatePickUp = "5" //已取件
|
||
StateArrivedDestination = "6" //到达目的地
|
||
StateReceiverGetGoods = "10" //取件人已收货
|
||
StateOrderCancel = "-1" //订单取消
|
||
|
||
//订单小类
|
||
SendTypeHelpMeDeliver = 0 //帮我送(默认)
|
||
SendTypeHelpMeBuy = 1 //帮我买
|
||
//预约类型
|
||
SubscribeTypeRealTime = 0 //实时订单
|
||
SubscribeTypeReservation = 1 //预约取件时间
|
||
//加急配送 默认不开启
|
||
UrgentOrderNormal = 0 //正常配送
|
||
UrgentOrderOpen = 1 //开启加急配送
|
||
//推送方式
|
||
PushTypeOpen = 0 //开放订单
|
||
PushTypeTest = 1 //测试订单
|
||
//特殊处理类型
|
||
SpecialTypeYes = 1 //需要
|
||
SpecialTypeNo = 0 //不需要
|
||
//取件是否需要打电话
|
||
CallMeWithTakeYes = 1 //需要
|
||
CallMeWithTakeNo = 0 //不需要
|
||
//支付方式
|
||
PayTypeBalance = 0 //账户余额支付 默认
|
||
PayTypeEnterprise = 1 //企业支付
|
||
//订单来源标识
|
||
OrderResourceMT = 1 //美团
|
||
OrderResourceELM = 2 //饿了么
|
||
OrderResourceOther = 3 //其他
|
||
|
||
)
|
||
|
||
var StateUuWaybill = map[string]string{
|
||
StateConfirmSuccess: "下单成功",
|
||
StateRMGrabsOrder: "跑男抢单",
|
||
StateArrivedStore: "已到达",
|
||
StatePickUp: "已取件",
|
||
StateArrivedDestination: "到达目的地",
|
||
StateReceiverGetGoods: "取件人已收货",
|
||
StateOrderCancel: "订单取消",
|
||
}
|
||
var SendType = map[int]string{
|
||
SendTypeHelpMeDeliver: "帮我送",
|
||
SendTypeHelpMeBuy: "帮我买",
|
||
}
|
||
|
||
type API struct {
|
||
openid string `json:"openid"` //用户openid,详情见 获取openid接口
|
||
appid string `json:"appid"` //appid
|
||
appKey string `json:"appkey"` //app密钥
|
||
sign string `json:"sign"` //加密签名
|
||
noncestr string `json:"nonce_str"` //随机字符串,不长于32位
|
||
timestamp string `json:"timestamp"` //时间戳,以秒计算时间,即unix-timestamp
|
||
locker sync.RWMutex
|
||
client *http.Client
|
||
config *platformapi.APIConfig
|
||
}
|
||
type BaseReqInfo struct {
|
||
Sign string `json:"sign"` //加密签名
|
||
NonceStr string `json:"nonce_str"` //随机字符串,不长于32位
|
||
Timestamp string `json:"timestamp"` //时间戳,以秒计算时间,即unix-timestamp
|
||
OpenID string `json:"openid"` //用户openid,详情见 获取openid接口
|
||
AppID string `json:"appid"` //appid
|
||
}
|
||
|
||
type BaseRespInfo struct {
|
||
Sign string `json:"sign"` //加密签名
|
||
NonceStr string `json:"nonce_str"` //随机字符串,不长于32位
|
||
AppID string `json:"appid"` //第三方用户唯一凭证
|
||
ReturnMsg string `json:"return_msg"` //返回信息,如非空,为错误原因,如签名失败、参数格式校验错误
|
||
ReturnCode string `json:"return_code"` //状态,ok/fail表示成功
|
||
}
|
||
|
||
//计算订单价格请求体
|
||
type GetOrderPriceReq struct {
|
||
//必填
|
||
//BaseReqInfo *BaseReqInfo
|
||
OriginID string `json:"origin_id"` //第三方对接平台订单id
|
||
FromAddress string `json:"from_address"` //发货地址
|
||
ToAddress string `json:"to_address"` //收货人地址
|
||
CityName string `json:"city_name"` //订单所在城市名 称(如郑州市就填”郑州市“,必须带上“市”)
|
||
SendType string `json:"send_type"` //订单小类 0帮我送(默认) 1帮我买
|
||
ToLat string `json:"to_lat"` //收货地址坐标纬度(坐标系为百度地图坐标系)
|
||
ToLng string `json:"to_lng"` //收货地址坐标经度(坐标系为百度地图坐标系)
|
||
FromLat string `json:"from_lat"` //发货地址坐标纬度(坐标系为百度地图坐标系)
|
||
FromLng string `json:"from_lng"` //发货地址坐标经度(坐标系为百度地图坐标系)
|
||
//非必填
|
||
FromUserNote string `json:"from_usernote"` //发货详细地址具体门牌号或门店名称
|
||
ToUserNote string `json:"to_usernote"` //收货人详细地址具体门牌号
|
||
//CountyName string `json:"county_name"` //订单所在县级地名称(如金水区就填“金水区”)
|
||
//SubscribeTime string `json:"subscribe_time"` //预约时间(如:2015-06-18 12:00:00)没有可以传空字符串
|
||
//SubscribeType string `json:"subscribe_type"` //预约类型 0实时订单 1预约取件时间
|
||
//GoodsType string `json:"goods_type"` //物品类型:(美食、鲜花、蛋糕、手机、钥匙、文件、其他)仅支持指定类型不包含按其他发布
|
||
//CouponID string `json:"coupon_id"` //优惠券ID(如果传入-1就不用优惠券否则系统自动匹配)
|
||
//CouponType string `json:"coupon_type"` //优惠券类型 默认空 个人优惠券 1=企业优惠券(必须企业帐号才可以使用)
|
||
//GoodsWeight int `json:"goods_weight"` //物品重量单位:KG(按城市标准进行超重计费)
|
||
//ShopID int64 `json:"shop_id"` //门店编号(门店列表可查看门店编号)
|
||
//GoodsPrice int `json:"goods_price"` //商品保价:价格(1-10000)按照一定费率收取保价费用
|
||
//UrgentOrder string `json:"urgent_order"` //加急配送默认不开启(0=正常配送 1=开启加急配送)
|
||
}
|
||
|
||
//计算订单价格返回体
|
||
type GetOrderPriceResp struct {
|
||
//必返回
|
||
OriginID string `json:"origin_id"` //第三方对接平台订单id
|
||
TotalMoney string `json:"total_money"` //订单总金额(优惠前)
|
||
NeedPayMoney string `json:"need_paymoney"` //实际需要支付金额
|
||
TotalPriceOff string `json:"total_priceoff"` //总优惠金额
|
||
Distance string `json:"distance"` //配送距离(单位:米)
|
||
CouponAmount string `json:"coupon_amount"` //优惠券金额
|
||
AddFee string `json:"addfee"` //加价金额
|
||
GoodsInsuranceMoney string `json:"goods_insurancemoney"` //商品保价金额
|
||
ExpiresIn string `json:"expires_in"` //price_token的过期时间(单位:秒)
|
||
//非必返回
|
||
PriceToken string `json:"price_token"` //金额令牌,提交订单前必须先计算价格
|
||
FreightMoney string `json:"freight_money"` //跑腿费,此字段废弃可忽略
|
||
CouponID string `json:"couponid"` //优惠券ID,此字段废弃可忽略
|
||
BaseRespInfo
|
||
}
|
||
|
||
//发布订单请求体
|
||
type AddOrderReq struct {
|
||
PriceToken string `json:"price_token"` //金额令牌,计算订单价格接口返回的price_token
|
||
OrderPrice string `json:"order_price"` //订单总金额(优惠前),计算订单价格接口返回的total_money
|
||
BalancePayMoney string `json:"balance_paymoney"` //实际需要支付金额,计算订单价格接口返回的need_paymoney
|
||
Receiver string `json:"receiver"` //收件人名称
|
||
ReceiverPhone string `json:"receiver_phone"` //收件人电话 手机号码; 虚拟号码格式(手机号_分机号码)例如:13700000000_1111
|
||
Note string `json:"note"` //订单备注 最长140个汉字
|
||
CallbackUrl string `json:"callback_url"` //订单提交成功后及状态变化的回调地址
|
||
PushType string `json:"push_type"` //推送方式(0 开放订单,2测试订单)默认传0即可
|
||
SpecialType string `json:"special_type"` //特殊处理类型,是否需要保温箱 1需要 0不需要
|
||
CallMeWithTake string `json:"callme_withtake"` //取件是否给我打电话 1需要 0不需要
|
||
PubUserMobile string `json:"pubusermobile"` //发件人电话,(如果为空则是用户注册的手机号)
|
||
PayType string `json:"pay_type"` //支付方式:1=企业支付 0账户余额支付(企业余额不足自动转账户余额支付)
|
||
OrderResource string `json:"orderresource"` //订单来源标示,示例(1=美团 2=饿了么 3=其他)
|
||
ShortOrderNum string `json:"shortordernum"` //订单平台短单号(0-10000),该单号会展示给骑手突出展示:“美团 #1”
|
||
ProductDetail string `json:"product_detail"` //商品详细信息:json格式字符串(建议请求接口encodeUrl处理)例如:[{"product_name":"幸福热奶茶(常规)","product_num":"2"},{"product_name":"香酥双鸡堡餐(常规)","product_num":"1"}]
|
||
ShopExpectTime string `json:"shop_expecttime"` //商家期望送达时间时间戳,以秒计算时间(仅用于展示给配送员)
|
||
ReceiverRealPhone string `json:"receiver_realphone"` //收件人真实脱敏电话(外卖订单虚拟号时,投递餐柜使用)格式:(137****0000或手机尾号0000)
|
||
}
|
||
|
||
//发布订单返回体
|
||
type AddOrderResp struct {
|
||
BaseRespInfo
|
||
OrderCode string `json:"ordercode"` //订单号
|
||
OriginID string `json:"origin_id"` //第三方对接平台订单id
|
||
}
|
||
|
||
//取消订单返回体
|
||
type CancelOrderResp struct {
|
||
BaseRespInfo
|
||
OrderCode string `json:"ordercode"` //订单号
|
||
OriginID string `json:"origin_id"` //第三方对接平台订单id
|
||
}
|
||
|
||
//获取订单详情返回体
|
||
type GetOrderDetailResp struct {
|
||
//必返
|
||
OriginID string `json:"origin_id"` //第三方对接平台id
|
||
SendType string `json:"send_type"` //订单小类 0帮我送 1帮我买
|
||
DriverLastloc string `json:"driver_lastloc"` //跑男的坐标,百度地图坐标系经纬度(格式:113.71776,34.767501)
|
||
//非返回
|
||
BaseRespInfo
|
||
OrderCode string `json:"order_code"` //uu跑腿订单编号
|
||
FromAddress string `json:"from_address"` //发货地址详细地址具体门牌号或门店名称
|
||
FromLat string `json:"from_lat"` //发货地址坐标纬度(坐标系为百度地图坐标系)
|
||
FromLng string `json:"from_lng"` //发货地址坐标经度(坐标系为百度地图坐标系)
|
||
ToAddress string `json:"to_address"` //收货人地址详细地址具体门牌号
|
||
ToLat string `json:"to_lat"` //收货地址坐标纬度(坐标系为百度地图坐标系)
|
||
ToLng string `json:"to_lng"` //收货地址坐标经度(坐标系为百度地图坐标系)
|
||
Distance string `json:"distance"` //订单距离
|
||
OrderPrice string `json:"order_price"` //订单总金额(优惠前),包含小费
|
||
Receiver string `json:"receiver"` //收件人
|
||
ReceiverPhone string `json:"receiver_phone"` //收件人电话
|
||
Note string `json:"note"` //订单备注
|
||
PriceOff string `json:"price_off"` //总优惠金额
|
||
State string `json:"state"` //当前状态1下单成功 3跑男抢单 4已到达 5已取件 6到达目的地 10收件人已收货 -1订单取消
|
||
AddTime string `json:"add_time"` //发单时间(格式2015-07-01 15:23:56)
|
||
FinishTime string `json:"finish_time"` //收货时间(格式2015-07-01 15:23:56)
|
||
StartLevel string `json:"start_level"` //评价星级
|
||
CommentNote string `json:"comment_note"` //评价内容
|
||
DriverName string `json:"driver_name"` //跑男姓名(跑男接单后)
|
||
DriverJobNum string `json:"driver_jobnum"` //跑男工号(跑男接单后)
|
||
DriverMobile string `json:"driver_mobile"` //跑男电话(跑男接单后)
|
||
ExpectedarriveTime string `json:"expectedarrive_time"` //跑男接单后预计到达时间(格式2015-07-01 15:23:56)取货前为到达取货地,取货后为到达收货地
|
||
}
|
||
|
||
type WaybillCallbackParam struct {
|
||
OrderCode string `json:"order_code"` //订单号
|
||
DriverName string `json:"driver_name"` //跑男姓名(跑男接单后)
|
||
DriverJobNum string `json:"driver_jobnum"` //跑男工号(跑男接单后)
|
||
DriverMobile string `json:"driver_mobile"` //跑男电话(跑男接单后)
|
||
State string `json:"state"` //当前状态 1下单成功 3跑男抢单 4已到达 5已取件 6到达目的地 10收件人已收货 -1订单取消
|
||
StateText string `json:"state_text"` //当前状态说明
|
||
OriginID string `json:"origin_id"` //第三方订单号
|
||
DriverPhoto string `json:"driver_photo"` //跑男头像(跑男接单后)
|
||
Sign string `json:"sign"` //加密签名
|
||
NonceStr string `json:"nonce_str"` //随机字符串,不长于32位
|
||
AppID string `json:"appid"` //第三方用户唯一凭证
|
||
ReturnMsg string `json:"return_msg"` //返回信息,如非空,为错误原因,如签名失败、参数格式校验错误
|
||
ReturnCode string `json:"return_code"` //状态,ok/fail表示成功
|
||
Timestamp string `json:"timestamp"`
|
||
//BaseRespInfo
|
||
}
|