Exemplo n.º 1
0
function EncryptedPin($sPin, $sCardNo, $sPubKeyURL)
{
    global $log;
    $sPubKeyURL = trim(SDK_ENCRYPT_CERT_PATH, " ");
    Think\Log::write("DisSpaces : " . PubKeyURL);
    $fp = fopen($sPubKeyURL, "r");
    if ($fp != NULL) {
        $sCrt = fread($fp, 8192);
        //		$log->LogInfo("fread PubKeyURL : " . $sCrt);
        fclose($fp);
    }
    $sPubCrt = openssl_x509_read($sCrt);
    if ($sPubCrt === FALSE) {
        print "openssl_x509_read in false!";
        return -1;
    }
    Think\Log::write($sPubCrt);
    //	$sPubKeyId = openssl_x509_parse($sCrt);
    Think\Log::write($sPubKeyId);
    $sPubKey = openssl_x509_parse($sPubCrt);
    Think\Log::write($sPubKey);
    //	openssl_x509_free($sPubCrt);
    //	print_r(openssl_get_publickey($sCrt));
    $sInput = Pin2PinBlockWithCardNO($sPin, $sCardNo);
    if ($sInput == 1) {
        print "Pin2PinBlockWithCardNO Error ! : " . $sInput;
        return 1;
    }
    $iRet = openssl_public_encrypt($sInput, $sOutData, $sCrt, OPENSSL_PKCS1_PADDING);
    if ($iRet === TRUE) {
        //		$log->LogInfo($sOutData);
        $sBase64EncodeOutData = base64_encode($sOutData);
        //print("PayerPin : " . $sBase64EncodeOutData);
        return $sBase64EncodeOutData;
    } else {
        print "openssl_public_encrypt Error !";
        return -1;
    }
}
Exemplo n.º 2
0
/**
 * 自定义异常处理
 * @param string $msg 异常消息
 * @param string $type 异常类型 默认为Think\Exception
 * @param integer $code 异常代码 默认为0
 * @return void
 */
function throw_exception($msg, $type = 'Think\\Exception', $code = 0)
{
    Think\Log::record('建议使用E方法替代throw_exception', Think\Log::NOTICE);
    if (class_exists($type, false)) {
        throw new $type($msg, $code);
    } else {
        Think\Think::halt($msg);
    }
    // 异常类型不存在则输出错误信息字串
}
Exemplo n.º 3
0
/**
 * D函数用于实例化模型类 格式 [资源://][模块/]模型
 * @param string $name 资源地址
 * @param string $layer 模型层名称
 * @return Model
 */
function D($name = '', $layer = '')
{
    if (empty($name)) {
        return new Think\Model();
    }
    static $_model = array();
    $layer = $layer ?: C('DEFAULT_M_LAYER');
    if (isset($_model[$name . $layer])) {
        return $_model[$name . $layer];
    }
    $class = parse_res_name($name, $layer);
    if (class_exists($class)) {
        $model = new $class(basename($name));
    } elseif (false === strpos($name, '/')) {
        // 自动加载公共模块下面的模型
        $class = '\\Common\\' . $layer . '\\' . $name . $layer;
        $model = class_exists($class) ? new $class($name) : new Think\Model($name);
    } else {
        Think\Log::record('D方法实例化没找到模型类' . $class, Think\Log::NOTICE);
        $model = new Think\Model(basename($name));
    }
    $_model[$name . $layer] = $model;
    return $model;
}
Exemplo n.º 4
0
/**
 * 如果操作失败则记录日志
 * @return array 格式:array('status'=>boolean,'info'=>'错误信息')
 * @author hebiduhebi@163.com
 */
function ifFailedLogRecord($result, $location)
{
    if ($result['status'] === false) {
        Think\Log::write($location . $result['info'], 'ERR');
    }
}
Exemplo n.º 5
0
/**
 * 处理报文中的文件
 *
 * @param unknown_type $params
 */
function deal_file($params)
{
    global $log;
    if (isset($params['fileContent'])) {
        Think\Log::write("---------处理后台报文返回的文件---------");
        $fileContent = $params['fileContent'];
        if (empty($fileContent)) {
            Think\Log::write('文件内容为空');
        } else {
            // 文件内容 解压缩
            $content = gzuncompress(base64_decode($fileContent));
            $root = SDK_FILE_DOWN_PATH;
            $filePath = null;
            if (empty($params['fileName'])) {
                Think\Log::write("文件名为空");
                $filePath = $root . $params['merId'] . '_' . $params['batchNo'] . '_' . $params['txnTime'] . '.txt';
            } else {
                $filePath = $root . $params['fileName'];
            }
            $handle = fopen($filePath, "w+");
            if (!is_writable($filePath)) {
                Think\Log::write("文件:" . $filePath . "不可写,请检查!");
            } else {
                file_put_contents($filePath, $content);
                Think\Log::write("文件位置 >:" . $filePath);
            }
            fclose($handle);
        }
    }
}
Exemplo n.º 6
0
 public function callback()
 {
     include_once APP_PATH . '/BaoyiPay/BaoyiPay.php';
     $xml = $_POST['data'];
     $info = xml2arr($xml);
     $body = $info['body'];
     //返回成功
     if ($body['state'] == '02') {
         // 结算成功
         Think\Log::write('业务号:(' . $body['tranSeqId'] . ')处理成功(02)');
         $pay = M('DrawcashList')->where(array('bussflowno' => $body['tranSeqId']))->find();
         if ($pay['status'] == 0) {
             //更新提现记录
             $drawcashlist = array('id' => $pay['id'], 'real_amount' => $body['amount'], 'submitdate' => $body['submitDate'], 'acctno' => $body['acctNo'], 'acctname' => $body['acctName'], 'state' => $body['state'], 'proctime' => $body['procTime'], 'remark' => $body['remark'], 'update_time' => NOW_TIME, 'status' => '1');
             M('CashFlow')->where(array('bussflowno' => $body['tranSeqId']))->save(array('state' => 1));
             M('DrawcashList')->save($drawcashlist);
         }
     } elseif ($body['state'] == '03') {
         // 结算失败
         Think\Log::write('业务号:(' . $body['tranSeqId'] . ')结算失败(03)');
         //查看交易记录
         $pay = M('DrawcashList')->where(array('bussflowno' => $body['tranSeqId']))->find();
         if ($pay['status'] == 0) {
             //更新提现金额
             $productinfo = M('Product')->find($pay['pid']);
             $drawcash_amount = $productinfo['drawcash_amount'] - $body['amount'];
             $product = array('id' => $pay['pid'], 'drawcash_amount' => $drawcash_amount);
             M('Product')->save($product);
             //更新提现记录
             $drawcashlist = array('id' => $pay['id'], 'real_amount' => $body['amount'], 'submitdate' => $body['submitDate'], 'acctno' => $body['acctNo'], 'acctname' => $body['acctName'], 'state' => $body['state'], 'proctime' => $body['procTime'], 'remark' => $body['remark'], 'update_time' => NOW_TIME, 'status' => '2');
             M('DrawcashList')->save($drawcashlist);
         }
     } else {
         if ($body['state'] == '00') {
             Think\Log::write('业务号:(' . $body['tranSeqId'] . ')待结算(00)');
         } else {
             if ($body['state'] == '01') {
                 Think\Log::write('业务号:(' . $body['tranSeqId'] . ')处理中(01)');
             } else {
                 if ($body['state'] == '04') {
                     Think\Log::write('业务号:(' . $body['tranSeqId'] . ')处理中');
                 }
             }
         }
     }
 }
Exemplo n.º 7
0
 /**
  * 重新整理listFields数据,将原始的listFields转换为运行时状态。比如:valChange的转换。
  * fdn  字符串转化成了 中文字段
  * $original 保持原型 true 
  * **/
 public function getListFields($reNew = false, $original = false)
 {
     //dump('ssss');die;
     $Log = new \Think\Log();
     $Log->write($this->name . "->getListFields", 'INFO');
     //Log::write($this->name."->getListFields",LOG::INFO);
     if ($original) {
         return $this->listFields;
     }
     //     使用listFields的md5值,作为缓存名,形成唯一缓存,一点list改变,则缓存自动失效,随意无需renew
     // 		if($reNew || C("APP_DEBUG")){
     // 			$this->setCacheListFields();
     // 			return $this->cacheListFields;
     // 		}
     //dump($this->cacheListFields);exit;
     if (empty($this->cacheListFields)) {
         $cacheFile = '_fields/' . $this->name . "_listFields_" . $this->getListFieldsMd5();
         //dump($cacheFile);exit;
         $this->cacheListFields = F($cacheFile);
         // dump($this->cacheListFields);die;
         if (empty($this->cacheListFields)) {
             //die('ddee');
             $this->setCacheListFields($cacheFile);
         }
     }
     return $this->cacheListFields;
 }
Exemplo n.º 8
0
/**
 * 根据证书ID 加载 证书
 *
 * @param unknown_type $certId        	
 * @return string NULL
 */
function getPulbicKeyByCertId($certId)
{
    global $log;
    Think\Log::write('报文返回的证书ID>' . $certId);
    // 证书目录
    $cert_dir = SDK_VERIFY_CERT_DIR;
    Think\Log::write('验证签名证书目录 :>' . $cert_dir);
    $handle = opendir($cert_dir);
    if ($handle) {
        while ($file = readdir($handle)) {
            clearstatcache();
            $filePath = $cert_dir . '/' . $file;
            if (is_file($filePath)) {
                if (pathinfo($file, PATHINFO_EXTENSION) == 'cer') {
                    if (getCertIdByCerPath($filePath) == $certId) {
                        closedir($handle);
                        Think\Log::write('加载验签证书成功');
                        return getPublicKey($filePath);
                    }
                }
            }
        }
        Think\Log::write('没有找到证书ID为[' . $certId . ']的证书');
    } else {
        Think\Log::write('证书目录 ' . $cert_dir . '不正确');
    }
    closedir($handle);
    return null;
}