《抖音支付》担保支付-订单同步

担保支付的订单需要同步到抖音商场订单里

文档地址:https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/develop/server/ecpay/order/order-sync

 /**
     * 普通小程序订单订单状态,POI 订单可以忽略
     * 0:待支付
     * 1:已支付
     * 2:已取消(用户主动取消或者超时未支付导致的关单)
     * 4:已核销(核销状态是整单核销,即一笔订单买了 3 个券,核销是指 3 个券核销的整单)
     * 5:退款中
     * 6:已退款
     * 8:退款失败
     * 注意:普通小程序订单必传,担保支付分账依赖该状态
     *
     *
     * status 订单状态,建议采用以下枚举值:
     * 待支付
     * 已支付
     * 已取消
     * 已超时
     * 已核销
     * 退款中
     * 已退款
     * 退款失败
     *
     * @param open_id   用户openid
     * @param order_status
     * @param orderNo. 商户订单号
     * @param status
     * @param totalPrice 金额分
     * @return
     */
    public String pushOrder(String open_id , Integer order_status , String orderNo , String  status , Integer totalPrice){


        JSONArray list = new JSONArray();
        JSONObject item = new JSONObject();
        //这里的类型是string类型,不能是int!!!!!!
        item.put("item_code" , System.currentTimeMillis()+""); 
        item.put("img" , "https://jkyx-api.chiguavod.com/res/2023/07/25/20230725222859305.jpg");
        item.put("title" , "蜜宝充值");
        item.put("sub_title" , "蜜宝充值");
        item.put("price" , totalPrice);
        list.add(item);

        JSONObject orderDetail = new JSONObject();
        orderDetail.put("order_id" , orderNo); //开发测订单id
        orderDetail.put("create_time" , System.currentTimeMillis());
        orderDetail.put("status" , status);
        orderDetail.put("amount" , 1);
        orderDetail.put("total_price" , totalPrice);
        orderDetail.put("detail_url" , "pages/index/my/billDetail");
        orderDetail.put("item_list" , list); //子订单商品列表,不可为空


        JSONObject json = new JSONObject();
        String accessToken = getAccessToken();
        json.put("access_token",accessToken);
        json.put("app_name","douyin");
        json.put("open_id", open_id);
        json.put("order_status", order_status);
        json.put("order_type", 0);
        json.put("update_time", System.currentTimeMillis());
        json.put("order_detail", orderDetail.toJSONString());

        doPostJson("https://developer.toutiao.com/api/apps/order/v2/push",json.toJSONString(), "UTF-8");
        System.out.println("抖音订单同步");
        return "success";
    }
``



//获取AcessToken



  public String getAccessToken( ){

        JSONObject json = new JSONObject();
        json.put("appid" , appid);
        json.put("secret" , appSecret);
        json.put("grant_type" , "client_credential");

        String postJson = doPostJson("https://developer.toutiao.com/api/apps/v2/token",json.toJSONString(), "UTF-8");

        JSONObject jo =  JSONObject.parseObject(postJson);
        return jo.getJSONObject("data").getString("access_token");
    }





//post请求工具类


 public static String doPostJson(String url, String jsonStr, String charset) {
        HttpClient httpClient = null;
        HttpPost httpPost = null;
        String result = null;
        try {
            httpClient = new DefaultHttpClient();
            httpPost = new HttpPost(url);
            System.out.println("请求参数"+jsonStr);
            // 设置参数
            StringEntity s = new StringEntity(jsonStr,"utf-8");
            s.setContentEncoding("UTF-8");
            s.setContentType("application/json");
            httpPost.setHeader("Content-Type","application/json;charset=utf-8");
            httpPost.setEntity(s);
            org.apache.http.HttpResponse response = httpClient.execute(httpPost);
            if (response != null) {
                HttpEntity resEntity = response.getEntity();
                if (resEntity != null) {
                    result = EntityUtils.toString(resEntity, charset);
                }
                System.out.println("response body:" + result);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return result;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

pywanggui

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值