package com.diaoyun.zion;


import com.diaoyun.zion.chinafrica.vo.ShopifyConstant;
import com.diaoyun.zion.master.base.Result;
import com.diaoyun.zion.master.enums.ResultCodeEnum;
import com.diaoyun.zion.master.util.HttpClientUtil;
import com.github.pagehelper.PageInfo;
import com.google.gson.JsonArray;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.junit.Test;

import java.io.IOException;
import java.util.*;

import static com.github.pagehelper.page.PageMethod.startPage;

/**
 * 微信
 *
 * @author egan
 * @email egzosn@gmail.com
 * @date 2017/8/18
 */
public class PayTest {

    @Test
    public void test() throws IOException {
        Map<String, Object> params = new HashMap<>();
        params.put("fields", "product_type");
        String connection = HttpClientUtil.createConnection(ShopifyConstant.productTypeUrl(), params, "UTF-8");
        List list = new ArrayList();
        JSONArray products = JSONObject.fromObject(connection).getJSONArray("products");
        for (int i = 0; i < products.size(); i++) {
            String string = products.getString(i);
            JSONObject jsonObject = JSONObject.fromObject(string);
            String product_type = jsonObject.getString("product_type");
            if (!"".equals(product_type) && !list.contains(product_type)) {
                list.add(product_type);
            }
        }
        System.out.println(list);
    }

    @Test
    public void test1() {
        Result result = new Result();
        Map<String, Object> params = new HashMap<>();
        params.put("product_type", "Face");
        List list = new ArrayList<>();
        try {
            String data = HttpClientUtil.createConnection(ShopifyConstant.productTypeUrl(), params, "UTF-8");
            System.out.println("===========>>>>>>>>>"+data);
            JSONArray products = JSONObject.fromObject(data).getJSONArray("products");
            for (int i = 0; i < products.size(); i++) {
                JSONObject object = products.getJSONObject(i);
                list.add(object);
            }

//            System.out.println(list.size());
            System.err.println(products.get(1));
            JSONArray jsonArray = JSONArray.fromObject(list);
        } catch (IOException e) {
            result.setCode(ResultCodeEnum.QUERY_ERROR.getCode()).setMessage(e.getMessage());

        }
    }
}
