package com.miaxis.test;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.miaxis.JpcjApplication;
import com.miaxis.common.core.domain.entity.UserInfo;
import com.miaxis.common.utils.http.HttpUtils;
import com.miaxis.feign.dto.WxGzhBatchUser;
import com.miaxis.feign.service.IWxSendService;
import com.miaxis.spread.service.impl.WxSpreadRelationServiceImpl;
import com.miaxis.user.service.IUserInfoService;
import com.miaxis.wx.service.IWxGzhService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@ActiveProfiles("dev")
@SpringBootTest(classes = JpcjApplication.class)
@RunWith(SpringRunner.class)
public class NormalTest {


    @Resource
    WxSpreadRelationServiceImpl wxSpreadRelationService;

    @Resource
    IWxSendService wxSendService;
    @Resource
    IWxGzhService wxGzhService;
    @Resource
    IUserInfoService userInfoService;

    @Test
    public void test666() throws Exception {
        String gzhToken = wxGzhService.getGzhToken();
//        String res = wxSendService.userInfo(gzhToken, "ovKTX59m65qpQAd-Bh0AIc5KhW3Q", "zh_CN");
        List<UserInfo> list = userInfoService.list();
        int times = (list.size()-1)/100+1;
        for (int i= 0; i < times-1; i++){
            WxGzhBatchUser batchUser = new WxGzhBatchUser();
            List<JSONObject> jlist = new ArrayList<JSONObject>();
            for(int j=0+i*100;j<99+i*100;j++){
                JSONObject jo = new JSONObject();
                jo.put("lang","zh_CN");
                jo.put("openid",list.get(j).getOpenid());
                jlist.add(jo);
            }
            batchUser.setUser_list(jlist);
            String res = wxSendService.batchUserInfo(gzhToken,batchUser);
            System.out.println(res);
        }
        WxGzhBatchUser batchUser = new WxGzhBatchUser();
        List<JSONObject> jlist = new ArrayList<JSONObject>();
        for(int j=0+(times-1)*100;j<list.size()-1;j++){
            JSONObject jo = new JSONObject();
            jo.put("lang","zh_CN");
            jo.put("openid",list.get(j).getOpenid());
            jlist.add(jo);
        }
        batchUser.setUser_list(jlist);
        String res = wxSendService.batchUserInfo(gzhToken,batchUser);
        System.out.println("最后一次");
        System.out.println(res);




    }
    @Test
    public void test777() throws Exception {
        List<UserInfo> list = userInfoService.list(new QueryWrapper<UserInfo>().isNull("union_id"));
        System.out.println(list.size());
        int index =1 ;
        for (UserInfo userInfo : list){
            String res = wxSendService.userInfo( wxGzhService.getGzhToken(), userInfo.getOpenid(), "zh_CN");
            JSONObject jsonObject = JSONObject.parseObject(res);
            if (jsonObject.getString("unionid") ==null){
                System.out.println( index);
                index++;
                continue;
            }
            userInfo.setUnionId(jsonObject.getString("unionid"));

            index++;
        }
        userInfoService.updateBatchById(list);



    }

    @Test
    public void test4447() throws Exception {
        String gzhToken = wxGzhService.getGzhToken();
    }

    public static void main(String[] args) {
        String url ="https://sirius.kakamobi.cn/api/open/traffic-icon/icon-list.htm";
        String param = "_appName=jiakaozhushou&_clv=1024&_launch=8&_manufacturer=Apple&_network=wifi&_operator=T&_pkgName=cn.mucang.ios.jiakaobaodianhuoche&_platform=iphone&_product=%E9%A9%BE%E8%80%83%E5%AE%9D%E5%85%B8%E5%8A%A9%E6%89%8B&_productCategory=jiakaobaodian&_r=6edd66e6ce8fa26c21b8e9509f70ddf8&_renyuan=mucang&_system=iOS&_systemVersion=13.5&_v=H4sIAAAAAAAAE12QO04CYRSF7%2FN%2FZG5DdRsIa3ALosOQaQjMBE1Eos0fuwkaGnsTV%2BAyLOxdBXE9UkhjdZpz8uU7M7ueXXX%2BbIzMY9QxhhGmilLF4mIAacoAEhU4RFT2td083N7vulF89GAkCIh%2BZ0CkHo3jFEkCpKSniJRcz53GBKVpIGKp60ZLizUXGZKUZmjDIJkH4MGX9vPxfXz7PL5%2F%2BYttltvLzud22L86Wc6pS5uepWfFVYY%2BrLln2qTVEnUl5OkM21kQ9K2x1%2F%2FMFCpCPxhkoph5UWJusbSsTVGWecEQF0kUTwK17%2F%2FGYcwywlyRVKdHJhdPv8lP2EY3AQAA&_vendor=appstore&_version=8.13.2&_webviewVersion=4.7&authToken=d84aa6f07ef5cda9a555e7c44af0f5a9d2328773&bizCode=8.13.2&carType=car&groupId=1&patternCode=101&sceneCode=101&score12=0&sign=90620500420099af09ae692c81d3ed21";
        String s = HttpUtils.sendGet(url, param);
        //JSONObject j
        System.out.println(s);
    }
























}
