手机号码充值地址:http://wapgd.189.cn/TS/weixin/new/cz.htm?cmpid=weixin-gdkf-server-cz&winzoom=1&wxapp=true&openId=orLiJju2pHCirkyUHDMz_4jhVkGc&from=groupmessage

 

一、网站分析

1)、用浏览器打开网站,F12打开  开发者调试工具,切换到Network

PHP curl--电信手机号码话费余额

2)、输入手机号码,点击査欠费,观察请求,查看响应结果

PHP curl--电信手机号码话费余额查看

PHP curl--电信手机号码话费余额

通过以上分析,获得话费的余额查询接口地址和所需的参数,下面开始用PHP完成接口信息的获取

二、PHP Curl请求接口

<?php

//1、设置查询的手机号码
$phone="173xxxxxxx";

$result=[];
//2、模拟查询5次
for ($i=0; $i < 5; $i++) { 
	$url_page ="http://wapgd.189.cn/getBalanceJson.do?latn_id=020&busiType=CDMA&chargeNum=".$phone."&Order_url=WTouch&chargeType=5BA";
	$user_agentArray = array(
		"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36",
	);
	$proxyArray = array(
		"http://110.52.235.130:9999" //代理ip和端口,测试时可去以下网站获取代理ip,http://ip.zdaye.com/dayProxy.html
	);
	$proxy = empty($proxyArray) ? "" : $proxyArray[rand(0, count($proxyArray) - 1)];
	$user_agent = $user_agentArray[rand(0, count($user_agentArray) - 1)];
	$rs=curl_string($url_page,$user_agent, $proxy,$proxyport);
	$result[$i]=$rs;
}
//3、格式化打印结果
echo "<pre>";
var_dump($result);



//生成随机IP
function Rand_IP(){
    $ip2id= round(rand(600000, 2550000) / 10000); //第一种方法,直接生成
    $ip3id= round(rand(600000, 2550000) / 10000);
    $ip4id= round(rand(600000, 2550000) / 10000);
    //下面是第二种方法,在以下数据中随机抽取
    $arr_1 = array("218","218","66","66","218","218","60","60","202","204","66","66","66","59","61","60","222","221","66","59","60","60","66","218","218","62","63","64","66","66","122","211");
    $randarr= mt_rand(0,count($arr_1)-1);
    $ip1id = $arr_1[$randarr];
    return $ip1id.".".$ip2id.".".$ip3id.".".$ip4id;
}
//curl函数
function curl_string ($url,$user_agent,$proxy,$proxyport){
	$ch = curl_init();
	// 有代理IP就使用代理
	if (!empty($proxy)) 
	{ 
		curl_setopt ($ch, CURLOPT_PROXY, $proxy); // 使用代理IP
		// 伪造客户端来源IP
		$xforip = rand(1, 254).".".rand(1, 254).".".rand(1, 254).".".rand(1, 254);
		curl_setopt ($ch, CURLOPT_HTTPHEADER, array('CLIENT-IP:'.$xforip, 'X-FORWARDED-FOR:'.$xforip));
	}
	curl_setopt ($ch, CURLOPT_URL, $url);
	curl_setopt ($ch, CURLOPT_POSTFIELDS, 'article_id=10898');
	curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent); //模拟用户使用的浏览器
	curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
	curl_setopt ($ch, CURLOPT_AUTOREFERER, 1 ); // 自动设置Referer
	curl_setopt ($ch, CURLOPT_TIMEOUT, 120);
	$result = curl_exec ($ch);
	curl_close($ch);
	return $result;
}

测试结果如下:

PHP curl--电信手机号码话费余额

注:此案例仅学习使用,请勿做任何违法行为!

相关文章:

  • 2022-12-23
  • 2021-11-29
  • 2022-01-15
  • 2022-02-07
  • 2022-02-17
  • 2021-12-25
  • 2021-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-05
  • 2021-12-15
  • 2021-09-21
  • 2021-12-23
  • 2021-12-21
相关资源
相似解决方案