123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- namespace app\common\library;
- use app\common\model\Config;
- use think\Controller;
- // +----------------------------------------------------------------------
- // | JuhePHP [ NO ZUO NO DIE ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
- // +----------------------------------------------------------------------
- // | Author: Juhedata <info@juhe.cn-->
- // +----------------------------------------------------------------------
- //----------------------------------
- // 聚合数据-手机话费充值API调用类
- //----------------------------------
- class JuheRecharge {
- private $appkey;
- private $openid;
- private $telCheckUrl = 'http://op.juhe.cn/ofpay/mobile/telcheck';
- private $telQueryUrl = 'http://op.juhe.cn/ofpay/mobile/telquery';
- private $submitUrl = 'http://op.juhe.cn/ofpay/mobile/onlineorder';
- private $staUrl = 'http://op.juhe.cn/ofpay/mobile/ordersta';
- public function __construct(){
- $this->appkey = Config::get_values('juhe_appkey');
- $this->openid = Config::get_values('juhe_openid');
- }
- /**
- * 根据手机号码及面额查询是否支持充值
- * @param string $mobile [手机号码]
- * @param int $pervalue [充值金额]
- * @return boolean
- */
- public function telcheck($mobile,$pervalue){
- $params = 'key='.$this->appkey.'&phoneno='.$mobile.'&cardnum='.$pervalue;
- $content = $this->juhecurl($this->telCheckUrl,$params);
- $result = $this->_returnArray($content);
- return $result;
- // print_r($result);die;
- // if($result['error_code'] == '0'){
- // return true;
- // }else{
- // return false;
- // }
- }
- /**
- * 根据手机号码和面额获取商品信息
- * @param string $mobile [手机号码]
- * @param int $pervalue [充值金额]
- * @return array
- */
- public function telquery($mobile,$pervalue){
- $params = 'key='.$this->appkey.'&phoneno='.$mobile.'&cardnum='.$pervalue;
- $content = $this->juhecurl($this->telQueryUrl,$params);
- return $this->_returnArray($content);
- }
- /**
- * 提交话费充值
- * @param [string] $mobile [手机号码]
- * @param [int] $pervalue [充值面额]
- * @param [string] $orderid [自定义单号]
- * @return [array]
- */
- public function telcz($mobile,$pervalue,$orderid){
- $pervalue = floatval($pervalue);
- $sign = md5($this->openid.$this->appkey.$mobile.$pervalue.$orderid);//校验值计算
- $params = array(
- 'key' => $this->appkey,
- 'phoneno' => $mobile,
- 'cardnum' => $pervalue,
- 'orderid' => $orderid,
- 'sign' => $sign
- );
- $content = $this->juhecurl($this->submitUrl,$params,1);
- return $this->_returnArray($content);
- }
- /**
- * 查询订单的充值状态
- * @param [string] $orderid [自定义单号]
- * @return [array]
- */
- public function sta($orderid){
- $params = 'key='.$this->appkey.'&orderid='.$orderid;
- $content = $this->juhecurl($this->staUrl,$params);
- return $this->_returnArray($content);
- }
- /**
- * 将JSON内容转为数据,并返回
- * @param string $content [内容]
- * @return array
- */
- public function _returnArray($content){
- return json_decode($content,true);
- }
- /**
- * 请求接口返回内容
- * @param string $url [请求的URL地址]
- * @param string $params [请求的参数]
- * @param int $ipost [是否采用POST形式]
- * @return string
- */
- public function juhecurl($url,$params=false,$ispost=0){
- $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 , 60 );
- curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
- 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;
- }
- }
|