package com.test.module.wb;

import com.alibaba.fastjson.JSONObject;
import com.test.HttpClient;

import java.util.HashMap;
import java.util.Map;


/**
 * 微博红包
 */
public class WBRedPackageUtil {

    String cookiePayer = "SUB=_2A25w2iDbDeRhGeVG41AZ9yzFwjiIHXVTrhUTrDV8PUNbmtBeLU7_kW9NT5g3XV_BxKEPBlmOrKVARBB-Qij8UX3j;";
    String cookieSeller = "SUB=_2A25w2j_9DeRhGeFP7FIS9C7FwjiIHXVTrhY1rDV8PUNbmtBeLRb8kW9NQRuyMZL8bWbkOfPntdKm37vjaxqU-18Z;";
    String uidSeller = "7170340994";


    /**
     * 获取支付的html
     *
     * @param money
     */
    public void getPayUrl(String money) {
        Map<String, String> mapPayer = new HashMap<>();
        mapPayer.put("X-Requested-With", "XMLHttpRequest");
        mapPayer.put("Referer", "http://mall.e.weibo.com/h5/redenvelope/create?sinainternalbrowser=topnav&msgtype=1&msgid=" + uidSeller + "&uicode=10000073&page=2&portrait_only=1");
        mapPayer.put("User-Agent", "Mozilla/5.0 (Linux; Android 5.1.1; DUK-AL20 Build/LMY48Z) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0 Safari/537.36 Weibo (HUAWEI-DUK-AL20__weibo__9.7.2.1__android__android5.1.1)");
        mapPayer.put("Cookie", cookiePayer);
        String order = HttpClient.doPost("http://mall.e.weibo.com/aj/redenvelope/create",
                "bag_type=1&puicode=10000073&msgtype=1&msgid=3882872994&singalAmount=" + money + "&blessing=快来抢，手快有，手慢无。恭喜发财！&count=1&amount=" + money + "&_t=0",
                null, mapPayer);


        JSONObject objectOrder = JSONObject.parseObject(order);
        mapPayer.clear();
        mapPayer.put("User-Agent", "Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Mobile Safari/537.36");
        mapPayer.put("Cookie", cookiePayer);
        HttpClient.doGet(objectOrder.getJSONObject("data").getString("url"),
                mapPayer);

    }


    /**
     * 查单
     *
     * @param tradeId
     */
    public void checkOrder(String tradeId) {
        Map<String, String> mapPayer = new HashMap<>();
        mapPayer.put("Cookie", cookiePayer);
        HttpClient.doPost("https://pay.sc.weibo.com/aj/pc/biz/list",
                "biz_type=0&status=0&biz_id=" + tradeId + "&start_time=2019-11-21&end_time=2019-11-27&page=1&page_size=10",
                null,
                mapPayer);
    }


    /**
     * 用户发红包消息给拆红包人
     */
    public void sendRedpackage(String orderid) {
        Map<String, String> mapPayer = new HashMap<>();
        mapPayer.put("X-Requested-With", "XMLHttpRequest");
        mapPayer.put("User-Agent", "Mozilla/5.0 (Linux; Android 5.1.1; DUK-AL20 Build/LMY48Z) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0 Safari/537.36 Weibo (HUAWEI-DUK-AL20__weibo__9.7.2.1__android__android5.1.1)");
        mapPayer.put("Cookie", cookiePayer);
        String order = HttpClient.doPost("https://mall.e.weibo.com/aj/redenvelope/sendmsg",
                "msgid=" + uidSeller + "&msgtype=1&set_id=" + orderid + "&_t=0",
                null, mapPayer);
    }

    /**
     * 拆包
     */
    public void pickMoney(String orderid) {

        Map<String, String> mapSeller = new HashMap<>();
        mapSeller.put("Cookie", cookieSeller);
        mapSeller.put("x-user-agent", "HUAWEI-DUK-AL20__weibo__9.7.2.1__android__android5.1.1");
        mapSeller.put("X-Requested-With", "com.sina.weibo");
        mapSeller.put("User-Agent", "Mozilla/5.0 (Linux; Android 5.1.1; DUK-AL20 Build/LMY48Z) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0 Safari/537.36 Weibo (HUAWEI-DUK-AL20__weibo__9.7.2.1__android__android5.1.1)");
        HttpClient.doGet("https://mall.e.weibo.com/h5/redenvelope/draw?set_id=" + orderid + "&sinainternalbrowser=topnav&portrait_only=1&from=1097295010&weiboauthoruid= ",
                mapSeller);
    }
}
