PHP查询移动、联通、电信话费余额函数示例

function getBalance($mobile) {
    $API_KEY = '5645226545SD6F';// 控制台密钥
    $API_URL = 'https://www.acbapi.com/api/huafei';// 接口地址
    $sk = '12345674898897489789498';// 32位自定义
       
    // 判断号码所属运营商
    $yd = array("134", "135", "136", "137", "138", "139", "144", "147", "148", "150", "151", "152", "157", "158", "159", "165", "170", "172", "178", "182", "183", "184", "187", "188", "195", "198");
    $lt = array("130", "131", "132", "155", "156", "166", "175", "176", "185", "186");
    $dx = array("133", "149", "153", "173", "177", "180", "181", "189", "190", "191", "193", "199");

    $isp = "";
    $yys = "";
    $prefix = substr($mobile, 0, 3);
    if (in_array($prefix, $yd)) {
        $isp = 'yd';
        $yys = '中国移动';
    } else if (in_array($prefix, $lt)) {
        $isp = 'lt';
        $yys = '中国联通';
    } else if (in_array($prefix, $dx)) {
        $isp = 'dx';
        $yys = '中国电信';
    } else {
        // handle error here if prefix does not match any known carrier
    }

    $get_post_data = array(
        'key' => $API_KEY,
        'mobile' => $mobile,
        'isp' => $isp,
        'order' => time(),
    );
    
    $resdata = api::send($API_URL, $get_post_data, 'POST', false, $sk);
    $response = json_decode($resdata, true);
    $response['yys'] = $yys;
    return $response;
    
}

上篇内容漏了isp的调用方法了,直接本地识别是哪个运营商的,但是也有弊端,运营商更新了,号段不在这里面就查询失败了 。

┭┮﹏┭┮

  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
PHP字符串函数可以分为以下几类: 1. 字符串操作函数:用于对字符串进行操作,如拼接、替换、截取等。常用函数有:strlen、substr、str_replace、str_pad等。 示例: 获取字符串长度: ``` $str = "hello world"; $length = strlen($str); // $length = 11 ``` 截取字符串: ``` $str = "hello world"; $sub_str = substr($str, 0, 5); // $sub_str = "hello" ``` 替换字符串: ``` $str = "hello world"; $new_str = str_replace("world", "php", $str); // $new_str = "hello php" ``` 2. 字符串格式化函数:用于对字符串进行格式化,如大小写转换、去除空格等。常用函数有:strtolower、strtoupper、trim等。 示例: 将字符串转换为大写: ``` $str = "hello world"; $new_str = strtoupper($str); // $new_str = "HELLO WORLD" ``` 去除字符串中的空格: ``` $str = " hello world "; $new_str = trim($str); // $new_str = "hello world" ``` 3. 字符串查询函数:用于查询字符串中是否包含某个子串或者某个字符的位置。常用函数有:strpos、strrpos、strstr等。 示例查询字符串中是否包含某个子串: ``` $str = "hello world"; $pos = strpos($str, "world"); // $pos = 6 ``` 查询字符在字符串中最后一次出现的位置: ``` $str = "hello world"; $pos = strrpos($str, "o"); // $pos = 7 ``` 4. 字符串编码函数:用于对字符串进行编码和解码。常用函数有:urlencode、urldecode、base64_encode、base64_decode等。 示例: 将字符串进行 URL 编码: ``` $str = "hello world"; $new_str = urlencode($str); // $new_str = "hello+world" ``` 将字符串进行 Base64 编码: ``` $str = "hello world"; $new_str = base64_encode($str); // $new_str = "aGVsbG8gd29ybGQ=" ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值