Verification method: 1. Apply for the bank card four-element detection interface and obtain the interface request Key; 2. Call the interface API to make a request, process the data and return the result; 3. Use "$content=juheHttpRequest($apiUrl , $paramstring,1);" Get the content returned by the interface; 4. Process the returned content according to its own business logic and print the processing results.
The operating environment of this tutorial: windows7 system, PHP8.1 version, DELL G3 computer
Bank based on PHP Card four-element verification API interface calling example
Preliminary preparation
Application interface
Bank card four-element detection interface application address:https://www.juhe.cn/docs/api/id/213?s=cpphpcn
Self-service application to activate the SMS API and obtain the interface request key. (Currently, the interface only supports enterprise users)
PHP request code example
/** * 聚合银行卡四元素校验API发起请求-PHP代码 * 功能:检测输入的姓名、手机号码、身份证号码、银行卡号是否一致。 */ // 请求的接口URL $apiUrl = 'http://v.juhe.cn/verifybankcard4/query'; // 请求参数 $params = [ 'realname' => 'xxx', // 姓名 'idcard' => 'xxx', // 身份证号码 'bankcard' => 'xxx', // 银行卡号 'mobile' => 'xxx', // 手机号码 'key' => 'xxx', // 接口调用key,通过聚合平台申请开通 ]; $paramsString = http_build_query($params); // 发起接口请求 $response = juheHttpRequest($apiUrl, $paramsString, 1); // 处理接口返回结果,根据自身业务逻辑修改处理 $paramstring = http_build_query($params); $content = juheHttpRequest($apiUrl, $paramstring, 1); $result = json_decode($content, true); if ($result) { if ($result['error_code'] == 0) { // 请求成功,根据自身业务逻辑修改处理 $res = $result['result']['res']; if ($res == '1') { // 信息核验一致 echo "信息核验一致"; } else { // 信息核验不一致 echo "信息核验不一致"; } } else { // 请求异常,根据自身业务逻辑修改处理 echo "{$result['error_code']}:{$result['reason']}" . PHP_EOL; } } else { //可能网络异常等问题请求失败,根据自身业务逻辑修改处理 echo "请求失败"; } /** * 发起网络请求函数 * @param string $url 请求的URL * @param bool $params 请求的参数内容 * @param int $ispost 是否POST请求 * @return bool|string 返回内容 */ function juheHttpRequest($url, $params = false, $ispost = 0) { $httpInfo = []; $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_USERAGENT, 'JUHE API'); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt($ch, CURLOPT_TIMEOUT, 12); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if ($ispost) { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); curl_setopt($ch, CURLOPT_URL, $url); } else { if ($params) { curl_setopt($ch, CURLOPT_URL, $url . '?' . $params); } else { curl_setopt($ch, CURLOPT_URL, $url); } } $response = curl_exec($ch); if ($response === FALSE) { // echo "cURL Error: ".curl_error($ch); return false; } $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $httpInfo = array_merge($httpInfo, curl_getinfo($ch)); curl_close($ch); return $response; }
For detailed request parameter and return parameter format instructions, please Refer to the official interface document: https://www.juhe.cn/docs/api/id/213?s=cpphpcn
Recommended learning: "PHP Video Tutorial》
The above is the detailed content of How to verify the four elements of bank card in PHP. For more information, please follow other related articles on the PHP Chinese website!

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version
Chinese version, very easy to use

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft