联通话费查询

代码如下

import requests
import json
url = "https://m.client.10010.com/servicequerybusiness/balancenew/accountBalancenew.htm"

headers = {
    "Host": "m.client.10010.com",
    "Connection": "keep-alive",
    "Content-Length": "116",
    "Pragma": "no-cache",
    "Cache-Control": "no-cache",
    "Accept": "application/json, text/plain, */*",
    "User-Agent": 'Mozilla/5.0 (Linux; Android 11; Redmi Note 8 Build/RKQ1.201004.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/92.0.4515.131 Mobile Safari/537.36',
    "Content-Type": "application/x-www-form-urlencoded",
    "Origin": "https://img.client.10010.com",
    "X-Requested-With": "com.sinovatech.unicom.ui",
    "Sec-Fetch-Site": "same-site",
    "Sec-Fetch-Mode": "cors",
    "Sec-Fetch-Dest": "empty",
    "Referer": "https://img.client.10010.com/",
    "Accept-Encoding": "gzip, deflate",
    "Accept-Language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
}

# ecs_token 为base64编码
cookie = "ecs_token=eyJkYXRhIjoiMTMyYzJxxxxWVkNWU5NDIwZGE3YWE1ODk0NzYzZDc3MGVkZmFlMzk3NTFiNmI4OWRjNDQxZxxxxx2MyMzA3NTVlNTQ5MjBiNmM3MTg0NzZmZDI1NzBjOTIyYjhjMzBlYjVjZDhlNzYyMzViNjk4NTBkNTI1YWIzYmU3Y2E5NjZmOWE0MWRkYzAzN2UxYjgxYjQwNzY1OGVjY2YyY2Y1NDFjNGMyOTMyIiwidmVyc2lvbiI6IjAwIn0="
# data 为128位 为ASE加密
# {"data": "132c2e4af91b9e4e4f2c20409ed5e942xxxa5894763d770edfae39751bxxxx5224f61fde0cc230755e54920b6c718476fd2570c922b8c30eb5cd8e76235b69850d525ab3be7ca966f9a41ddc037e1b81b407658eccf2cf541c4c2932", "version": "00"}
# key和iv需要重新找
# key  6206c34e2186e752c74e6df32ab8fa5b
# iv   00e5d201c2c2acbff8154861242ba0c4

# cookie转字典
cookies = dict([l.split("=", 1) for l in cookie.split("; ")])
data = {
    "duanlianjieabc": "",
    "channelCode": "",
    "serviceType": "",
    "saleChannel": "",
    "externalSources": "",
    "contactCode": "",
    "language": "chinese",
    "channel": "client"
}
r = requests.post(url=url, headers=headers, data=data, cookies=cookies)
j = json.loads(r.text)
money = j['curntbalancecust']
allbillfee = j['allbillfee']
print("本月账单:"+str(allbillfee)+"  剩余话费:"+str(money))

ASE加解密(java)

AES/CBC/PKCS5Padding

AesUtil.java

package com.T;

public class AesUtil {
    private static final String iv = "00e5d201c2c2acbff8154861242ba0c4";
    private static final String key = "6206c34e2186e752c74e6df32ab8fa5b";

    public static String aesEncrypt(String str) {
        return EncodeUtils.hexEncode(Cryptos.aesEncrypt(str.getBytes(),
                EncodeUtils.hexDecode(key), EncodeUtils.hexDecode(iv)));
    }

    public static String aesDecrypt(String str) {
        return Cryptos.aesDecrypt(EncodeUtils.hexDecode(str),
                EncodeUtils.hexDecode(key), EncodeUtils.hexDecode(iv));
    }

    public static void main(String[] args) {
//        String ans="666" ;
//        String rs= aesEncrypt(ans);
//        System.out.println(rs);
        String ans2="132c2e4af91b9e4e4f2c20409ed5e9420da7aa5894763d770edfae39751b6b89dc441f5224f61fde0cc230755e54920b6c718476fd2570c922b8c30eb5cd8e76235b69850d525ab3be7ca966f9a41ddc037e1b81b407658eccf2cf541c4c2932" ;
        String rs2= aesDecrypt(ans2);
        System.out.println(rs2);
    }
}

Cryptos.java

package com.T;

import java.security.GeneralSecurityException;
import java.security.SecureRandom;

import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;


public class Cryptos {
    private static final String AES = "AES";
    private static final String AES_CBC = "AES/CBC/PKCS5Padding";
    private static final int DEFAULT_AES_KEYSIZE = 128;
    private static final int DEFAULT_IVSIZE = 16;
    private static SecureRandom random = new SecureRandom();


    public static byte[] aesEncrypt(byte[] input, byte[] key) {
        return aes(input, key, Cipher.ENCRYPT_MODE);
    }

    public static byte[] aesEncrypt(byte[] input, byte[] key, byte[] iv) {
        return aes(input, key, iv, Cipher.ENCRYPT_MODE);
    }


    public static String aesDecrypt(byte[] input, byte[] key) {
        byte[] decryptResult = aes(input, key, Cipher.DECRYPT_MODE);
        return new String(decryptResult);
    }


    public static String aesDecrypt(byte[] input, byte[] key, byte[] iv) {
        byte[] decryptResult = aes(input, key, iv, Cipher.DECRYPT_MODE);
        return new String(decryptResult);
    }


    private static byte[] aes(byte[] input, byte[] key, int mode) {
        try {
            SecretKey secretKey = new SecretKeySpec(key, AES);
            Cipher cipher = Cipher.getInstance(AES);
            cipher.init(mode, secretKey);
            return cipher.doFinal(input);
        } catch (GeneralSecurityException e) {
            // throw Exceptions.unchecked(e);
            return null;
        }
    }


    private static byte[] aes(byte[] input, byte[] key, byte[] iv, int mode) {
        try {
            SecretKey secretKey = new SecretKeySpec(key, AES);
            IvParameterSpec ivSpec = new IvParameterSpec(iv);
            Cipher cipher = Cipher.getInstance(AES_CBC);
            cipher.init(mode, secretKey, ivSpec);
            return cipher.doFinal(input);
        } catch (GeneralSecurityException e) {
            System.out.println(e);
            return null;
        }
    }

    public static byte[] generateAesKey() {
        return generateAesKey(DEFAULT_AES_KEYSIZE);
    }


    public static byte[] generateAesKey(int keysize) {
        try {
            KeyGenerator keyGenerator = KeyGenerator.getInstance(AES);
            keyGenerator.init(keysize);
            SecretKey secretKey = keyGenerator.generateKey();
            return secretKey.getEncoded();
        } catch (Exception e) {
            System.out.println(e);
            return null;
        }
    }

    public static byte[] generateIV() {
        byte[] bytes = new byte[DEFAULT_IVSIZE];
        random.nextBytes(bytes);
        return bytes;
    }

    public static void main(String[] args) {
        System.out.println(EncodeUtils.hexEncode(generateIV()));
        System.out.println(EncodeUtils.hexEncode(generateAesKey()));
    }
}


EncodeUtils.java

package com.T;

import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;

public class EncodeUtils {
    private static final String DEFAULT_URL_ENCODING = "UTF-8";


    public static String hexEncode(byte[] input) {
        return Hex.encodeHexString(input);
    }


    public static byte[] hexDecode(String input) {
        try {
            return Hex.decodeHex(input.toCharArray());
        } catch (DecoderException e) {
            throw new IllegalStateException("Hex Decoder exception", e);
        }
    }
}


测试

package com.itcase.searchmoney.utils;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;


public class search {
    private static String baseUrl ="https://weixin.10010js.com/app/charge/qryRealFee";
    public static String  searchMoney(String phone) throws IOException, JSONException {
//        参数
        StringBuilder param = new StringBuilder();
        JSONObject jsonObject =new JSONObject();
        jsonObject.put("phone",phone);
        byte[] postDataBytes = jsonObject.toString().getBytes("UTF-8");
//        post请求
        URL url = new URL(baseUrl);
        HttpURLConnection conn = (HttpURLConnection)url.openConnection();
        conn.setConnectTimeout(2000);
        conn.setReadTimeout(5000);
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Host", "weixin.10010js.com");
        conn.setRequestProperty("Content-Type", "application/json");
        conn.setRequestProperty("Cache-Control", "no-cache");
        conn.setRequestProperty("Content-Length", "23");
        conn.setRequestProperty("Accept", "*/*");
        conn.setRequestProperty("Referer", "https://weixin.10010js.com/actPage/activity/index28.html?");
        conn.setRequestProperty("Accept-Language", "zh-cn");
        conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Linux; U; Android 8.1.0; zh-cn; BLA-AL00 Build/HUAWEIBLA-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/8.9 Mobile Safari/537.36");
        //5. output,这里要记得开启输出流,将自己要添加的参数用这个输出流写进去,传给服务端,这是socket的基本结构
        conn.setDoOutput(true);
        conn.getOutputStream().write(postDataBytes);
        //获取内容
        BufferedReader bufferedReader = null;
        InputStream inputStream = conn.getInputStream();
        bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        final StringBuffer stringBuffer = new StringBuffer();
        String line = null;
        while ((line = bufferedReader.readLine()) != null) {
            stringBuffer.append(line);
        }
        double money =Double.valueOf(Integer.parseInt(stringBuffer.toString()) )/ 100.00;
        return String.valueOf(money);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值