千家信息网

如何用代码实现聚合接口对接

发表于:2024-09-29 作者:千家信息网编辑
千家信息网最后更新 2024年09月29日,本篇内容介绍了"如何用代码实现聚合接口对接"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
千家信息网最后更新 2024年09月29日如何用代码实现聚合接口对接

本篇内容介绍了"如何用代码实现聚合接口对接"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

'appkey',        'flow'=>'appkey',        'sinopec'=>'appkey',    );     public $openid = 'JH160141dd01f07b3149d99dad44802431';    public $appkey = '';     /**     * juheModel constructor.     * @param string $type tel 话费 flow 流量 sinopec 油卡     */    public function __construct($type)    {        switch($type){            case 'tel':                $this ->appkey = $this ->appkey_config['tel'];                break;            case 'flow':                $this ->appkey = $this ->appkey_config['flow'];                break;            case 'sinopec':                $this ->appkey = $this ->appkey_config['sinopec'];                break;        }    }     /**     * 【油卡】加油卡充值     * @param $proid     * @param $cardnum     * @param $orderid     * @param $game_userid     * @param $gasCardTel     * @param $gasCardName     * @param $chargeType     * @return mixed     */    public function order($proid,$cardnum,$orderid,$game_userid,$gasCardTel,$gasCardName,$chargeType)    {        $url = "http://op.juhe.cn/ofpay/sinopec/onlineorder";        $newkey = $this->openid.$this->appkey.$proid.$cardnum.$game_userid.$orderid;        $sign= md5($newkey);        $params = array(            "proid" => $proid,//产品id:10000(中石化50元加油卡)、10001(中石化100元加油卡)、10003(中石化500元加油卡)、10004(中石化1000元加油卡)、10007(中石化任意金额充值)、10008(中石油任意金额充值)            "cardnum" => $cardnum,//充值数量 任意充 (整数(元)),其余面值固定值为1            "orderid" => $orderid,//商家订单号,8-32位字母数字组合            "game_userid" => $game_userid,//加油卡卡号,中石化:以100011开头的卡号、中石油:以9开头的卡号            "gasCardTel" => $gasCardTel,//持卡人手机号码            "gasCardName" => $gasCardName,//持卡人姓名            "chargeType" => $chargeType,//加油卡类型 (1:中石化、2:中石油;默认为1)            "key" => $this->appkey,//应用APPKEY(应用详细页查询)            "sign" => $sign,//校验值,md5(OpenID+key+proid+cardnum+game_userid+orderid),OpenID在个人中心查询        );        $content = $this->juhecurl($url, $params);        $result = json_decode($content, true);        return $result;    }     /**     * 【油卡】油卡查询订单状态     * @param $orderid     * @return mixed     */    public function ordersta($orderid)    {        $url = "http://op.juhe.cn/ofpay/sinopec/ordersta";        $params = array(            "orderid" => $orderid,//商家订单号,8-32位字母数字组合            "key" => $this->appkey,//应用APPKEY(应用详细页查询)        );        $content = $this->juhecurl($url, $params);        $result = json_decode($content, true);        return $result;    }     /**     * 【流量】全部流量套餐列表     * @return mixed     */    public function flowlist()    {        //************1.全部流量套餐列表************        $url = "http://v.juhe.cn/flow/list";        $params = array(            "key" => $this->appkey,//应用APPKEY(应用详细页查询)        );        $paramstring = http_build_query($params);        $content = $this->juhecurl($url,$paramstring);        $result = json_decode($content,true);        return $result;    }     /**     * 【流量】检测号码支付的流量套餐     * @param $phone     * @return mixed     */    public function telcheck($phone)    {        //************2.检测号码支持的流量套餐************        $url = "http://v.juhe.cn/flow/telcheck";        $params = array(            "phone" => $phone,//要查询的手机号码            "key" => $this->appkey,//应用APPKEY(应用详细页查询)        );        $paramstring = http_build_query($params);        $content = $this->juhecurl($url,$paramstring);        $result = json_decode($content,true);        return $result;        //**************************************************    }     /**     * 【流量】检测号码购买的流量是否存在     * @param $phone     * @param $price     * @return bool     */    public function telpricecheck($phone,$price)    {        //************2.检测号码支持的流量套餐************        $url = "http://v.juhe.cn/flow/telcheck";        $params = array(            "phone" => $phone,//要查询的手机号码            "key" => $this->appkey,//应用APPKEY(应用详细页查询)        );        $paramstring = http_build_query($params);        $content = $this->juhecurl($url,$paramstring);        $result = json_decode($content,true);        if($result){            if($result['error_code']=='0'){                $product=$result['result'][0];                $flows=$result['result'][0]['flows'];                if($flows && count($flows)>0)                {                    foreach ($flows as $flow)                    {                        if($flow['p']==$price)                        {                            $product['item']=$flow;                            return $product;                        }                    }                }                return false;            }else{                return false;            }        }else{            return false;        }        //**************************************************    }     /**     * 【流量】提交流量充值     * @param $phone     * @param $pid     * @param $orderid     * @return mixed     */    public function recharge($phone,$pid,$orderid)    {        //************3.提交流量充值************        $newkey = $this->openid.$this->appkey.$phone.$pid.$orderid;        $sign= md5($newkey);        $url = "http://v.juhe.cn/flow/recharge";        $params = array(            "phone" => $phone,//需要充值流量的手机号码            "pid" => $pid,//流量套餐ID            "orderid" => $orderid,//自定义订单号,8-32字母数字组合            "key" => $this->appkey,//应用APPKEY(应用详细页查询)            "sign" => $sign,//校验值,md5(OpenID+key+phone+pid+orderid),结果转为小写        );        $paramstring = http_build_query($params);        $content = $this->juhecurl($url,$paramstring);        $result = json_decode($content,true);        return $result;        //**************************************************    }    /**     * 【流量】订单状态查询     * @param $orderid     * @return mixed     */    public function orderstaflow($orderid)    {        //************4.订单状态查询************        $url = "http://v.juhe.cn/flow/ordersta";        $params = array(            "orderid" => $orderid,//商家订单号,8-32位字母数字组合,由您自己生成            "key"     => $this ->appkey, //应用APPKEY(应用详细页查询)        );        $paramstring = http_build_query($params);        $content = $this->juhecurl($url,$paramstring);        $result = json_decode($content,true);        return $result;        //**************************************************    }     /**     * 【话费】检测手机号是否能充值     * @param $phone     * @param $cardnum     * @return mixed     */    public function telcheckmobile($phone,$cardnum)    {        //************1.检测手机号码是否能充值************        $url = "http://op.juhe.cn/ofpay/mobile/telcheck";        $params = array(            "phoneno" => $phone,//要查询的手机号码            "cardnum" => $cardnum,//充值金额,目前可选:10、20、30、50、100、300            "key"     => $this ->appkey //应用APPKEY(应用详细页查询)        );        $paramstring = http_build_query($params);        $content = $this->juhecurl($url,$paramstring);        $result = json_decode($content,true);        return $result;        //**************************************************    }     /**     * 【话费】根据手机号和面值查询商品     * @param $phone     * @param $cardnum     * @return mixed     */    public function telquery($phone,$cardnum)    {        //************2.根据手机号和面值查询商品************        $url = "http://op.juhe.cn/ofpay/mobile/telquery";        $params = array(            "phoneno" => $phone,//要查询的手机号码            "cardnum" => $cardnum,//充值金额,目前可选:10、20、30、50、100、300            "key"     => $this ->appkey //应用APPKEY(应用详细页查询)        );        $paramstring = http_build_query($params);        $content = $this->juhecurl($url,$paramstring);        $result = json_decode($content,true);        return $result;        //**************************************************    }     /**     * 【话费】手机直充接口     * @param $phone     * @param $cardnum     * @param $orderid     * @return mixed     */    public function onlineorder($phone,$cardnum,$orderid)    {        //************3.手机直充接口************        $url = "http://op.juhe.cn/ofpay/mobile/onlineorder";        $newkey = $this->openid.$this->appkey.$phone.$cardnum.$orderid;        $sign= md5($newkey);        $params = array(            "phoneno" => $phone,//要查询的手机号码            "cardnum" => $cardnum,//充值金额,目前可选:10、20、30、50、100、300            "orderid" => $orderid,//商家订单号,8-32位字母数字组合,由您自己生成            "key"     => $this ->appkey, //应用APPKEY(应用详细页查询)            "sign"     => $sign //校验值,md5(OpenID+key+phoneno+cardnum+orderid),OpenID在个人中心查询        );        $paramstring = http_build_query($params);        $content = $this->juhecurl($url,$paramstring);        $result = json_decode($content,true);        return $result;        //**************************************************    }     /**     * 【话费】订单状态查询     * @param $orderid     * @return mixed     */    public function orderstamobile($orderid)    {        //************4.订单状态查询************        $url = "http://op.juhe.cn/ofpay/mobile/ordersta";        $params = array(            "orderid" => $orderid,//商家订单号,8-32位字母数字组合,由您自己生成            "key"     => $this ->appkey, //应用APPKEY(应用详细页查询)        );        $paramstring = http_build_query($params);        $content = $this->juhecurl($url,$paramstring);        $result = json_decode($content,true);        return $result;        //**************************************************    }     /**     * 【公共】请求接口返回内容     * @param  string $url [请求的URL地址]     * @param  string $params [请求的参数]     * @param  int $ispost [是否采用POST形式]     * @return  string     */    function juhecurl($url,$params='',$ispost=0){        $params = htmlspecialchars_decode($params);        $httpInfo = array();        $ch = curl_init();        curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );        curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );        curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 3600 );        curl_setopt( $ch, CURLOPT_TIMEOUT , 3600);        curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );        curl_setopt( $ch, CURLOPT_FOLLOWLOCATION , true);        if( $ispost )        {            curl_setopt( $ch , CURLOPT_POST , true );            $paramstring = http_build_query($params);            curl_setopt( $ch , CURLOPT_POSTFIELDS , $paramstring );            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 );        logInfo($url.'-请求地址','juhe_push','JuheLog');        logInfo(json_encode($params).'-请求数据','juhe_push','JuheLog');        logInfo($response.'-返回数据','juhe_push','JuheLog');        if ($response === FALSE) {            return false;        }        //$httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );        //$httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );        curl_close( $ch );        return $response;    } }

"如何用代码实现聚合接口对接"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!

0