https://www.juhe.cn/ucenter/datacenter(聚合三方类)

本文介绍了一个聚合接口服务模型,该模型包含话费、流量及油卡充值服务。通过不同的API接口,可以实现充值、订单状态查询、套餐列表获取等功能。模型使用PHP语言实现,包括了构造函数、请求接口返回内容等关键方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/5/23 0023
 * Time: 13:47
 */

namespace app\service;

/**
 * 聚合接口模型.
 *
 * @version TS4.5
 * @name JuheModel
 *
 * @author Foreach
 */
class JuheService
{
    public $appkey_config = array(
        'tel'=>'3bd754fa428e72b2c82acaac5d156a98',
        'flow'=>'319defcc61d663695d28ba257cd9b9f1',
        'sinopec'=>'7827db28dffaeb92454b1e508b4039b8',
    );

    public $openid = 'JHa3bb958f001fc7a153553cdd9a17d059';
    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在个人中心查询
        );
        $paramstring = http_build_query($params);
        $content = $this->juhecurl($url, $paramstring);
        $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(应用详细页查询)
        );
        $paramstring = http_build_query($params);
        $content = $this->juhecurl($url, $paramstring);
        $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(<b>OpenID</b>+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,//充值金额,目前可选:1、2、5、10、20、30、50、100、200、300、500
            "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;
    }


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值