[getpy 汉字转拼音函数]
@DateTime 2018-10-08
@param    [type]     $s       [汉字字符串]
@param    boolean    $quanpin [是否全拼]
@param    boolean    $daxie   [首字母是否大写]
@return   [string]            [description]
358612
public static function getpy($s, $quanpin = true, $daxie = false) {        
        $s = preg_replace("/\s/is", "_", $s);        
        $s = preg_replace("/(|\~|\`|\!|\@|\#|\$|\%|\^|\&|\*|\(|\)|\-|\+|\=|\{|\}|\[|\]|\||\\|\:|\;|\"|\'|\<|\,|\>|\.|\?|\/)/is", "", $s);
        $i = 0;        
        $py = '';        // 加入这一句，自动识别UTF-8        
        if (strlen("拼音") > 4){
            $s = @iconv('UTF-8', 'GBK', $s);
        }
        if ($quanpin) {
            // 全拼
            for ($i = 0; $i < strlen($s); $i++) {                
                if (ord($s[$i]) > 128) {                    
                    $char = self::asi2py(ord($s[$i]) + ord($s[$i + 1]) * 256);                    
                    $py.=$char;
                    $i++;
                } else {
                    $py.=$s[$i];
                }
            }
        } else {
            // 首字母            
            for ($i = 0; $i < strlen($s); $i++) { 
                if (ord($s[$i]) > 128) {
                    $char = self::asi2py(ord($s[$i]) + ord($s[$i + 1]) * 256); 
                    $py  .=$char[0];
                    $i++;
                } else { 
                    $py .=$s[$i];
                }
            }
        }
        // 判断是否输出小写字符        
        return ($daxie == true ? $py : strtolower($py));    
    }
1270657
public function cardApiTicket($jus = false)
    {
        $key        = $this->getAppId() . 'card_api_ticket';
        $api_ticket = $this->cache($key);

        if (false == $api_ticket || $jus) {
            $this->apitype = 'cgi-bin';
            $this->module  = 'ticket';

            $queryStr = ['type' => 'wx_card'];

            $res = $this->_get('getticket', $queryStr);

            if (false === $res) {
                exit('获取Card Api Ticket失败!');
            }

            $api_ticket = $res['ticket'];

            $this->cache($key, $api_ticket, 3000);
        }

        return $api_ticket;
    }
1265085
def for_sz(code):
    

    if str(code)[0:2] in ['00', '30', '02']:
        return 'stock_cn'
    elif str(code)[0:2] in ['39']:
        return 'index_cn'
    elif str(code)[0:2] in ['15']:
        return 'etf_cn'
    elif str(code)[0:2] in ['10', '11', '12', '13']:
        # 10xxxx 国债现货
        # 11xxxx 债券
        # 12xxxx 可转换债券
        # 12xxxx 国债回购
        return 'bond_cn'

    elif str(code)[0:2] in ['20']:
        return 'stockB_cn'
    else:
        return 'undefined'
384355
private function _getAddressInfo($addressCode, $birthdayCode)
    {
        $addressInfo = [
            'province' => '',
            'city'     => '',
            'district' => '',
        ];

        // 省级信息
        $provinceAddressCode = substr($addressCode, 0, 2).'0000';
        $addressInfo['province'] = $this->_getAddress($provinceAddressCode, $birthdayCode);

        $firstCharacter = substr($addressCode, 0, 1); // 用于判断是否是港澳台居民居住证（8字开头）

        // 港澳台居民居住证无市级、县级信息
        if ($firstCharacter == '8') {
            return $addressInfo;
        }

        // 市级信息
        $cityAddressCode = substr($addressCode, 0, 4).'00';
        $addressInfo['city'] = $this->_getAddress($cityAddressCode, $birthdayCode);

        // 县级信息
        $addressInfo['district'] = $this->_getAddress($addressCode, $birthdayCode);

        return empty($addressInfo) ? false : $addressInfo;
    }
551625
public function QPayOrderQuery($params = array()){
        /*        //入参
                $params = array();
                $params["out_trade_no"] = "20160512161914_BBC";
                $params["sub_mch_id"] = "1900005911";*/
        if (empty($params["out_trade_no"])){
            throw new Exception('商户订单号参数不能缺少' ,'OUT_TRADE_NO_MUST_INPUT');
        }
        if (empty($params["sub_mch_id"])){
            throw new Exception('sub_mch_id不能缺少' ,'FEE_TYPE');
        }

        //api调用
        $qpayApi = new QpayMchAPI('https://qpay.qq.com/cgi-bin/pay/qpay_order_query.cgi', null, 10);
        $qpayApi->setMchId('1490434181');
        $qpayApi->setMchKey('8525638f86969d1de5c51ad0494f4f13');
        $ret = $qpayApi->reqQpay($params);
        return QpayMchUtil::xmlToArray($ret);
    }
1282789
public function getWxPayJsApiParameters($prepayId)
    {
        // 获取jsapi支付的参数
        $input = [
            //微信分配的公众账号ID WxPayConfig::APPID
            'appId' => $this->appId,
            //设置支付时间戳
            'timeStamp' => (string)time(),
            //随机字符串
            'nonceStr' => SHA1::get_random_str(32),
            //订单详情扩展字符串
            'package' => 'prepay_id='.$prepayId,
            //签名方式
            'signType' => 'MD5',
        ];
        // 签名
        $input['paySign'] = SHA1::getSign2($input, 'key='.$this->key);
        return json_encode($input);
    }
1117998
static function instance( $input_charset_code, $output_charset_code, $use_cache = true )
    {
        $globalsKey = "eZCodePageMapper-$input_charset_code-$output_charset_code";

        if ( !isset( $GLOBALS[$globalsKey] ) ||
             !( $GLOBALS[$globalsKey] instanceof eZCodePageMapper ) )
        {
            $GLOBALS[$globalsKey] = new eZCodePageMapper( $input_charset_code, $output_charset_code, $use_cache );
        }

        return $GLOBALS[$globalsKey];
    }
13609
public function getOpenId($scope = 'snsapi_base'){
        if(isset($_GET['code'])){
            $code = $_GET['code'];
            $url = $this->apiUrl."/sns/oauth2/access_token?appid=".self::$config['appId']."&secret=".self::$config['appSecret']."&code={$code}&grant_type=authorization_code";
            $data = $this->curl($url);
            return $this->get($data);
        }else{
            $back_url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'].'?'.$_SERVER['QUERY_STRING'];
            $redirect_uri = urlencode($back_url);
            $code_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".self::$config['appId']."&redirect_uri=".$redirect_uri."&response_type=code&scope=".$scope."&state=STATE&connect_redirect=1#wechat_redirect";
            header("Location: $code_url");
            exit;
        }
    }
1194042
public static function to_gb2312($s, $isfirst = false)
    {
        $res = '';
        $len = strlen($s);
        $pinyin_arr = self::get_pinyin_array();
        for ($i = 0; $i < $len; $i++) {
            $ascii = ord($s[$i]);
            if ($ascii > 0x80) {
                $ascii2 = ord($s[++$i]);
                $ascii = $ascii * 256 + $ascii2 - 65536;
            }
            if ($ascii < 255 && $ascii > 0) {
                if (($ascii >= 48 && $ascii <= 57) || ($ascii >= 97 && $ascii <= 122)) {
                    $res .= $s[$i]; // 0-9 a-z
                } elseif ($ascii >= 65 && $ascii <= 90) {
                    $res .= strtolower($s[$i]); // A-Z
                } else {
                    $res .= '-';
                }
            } elseif ($ascii < -20319 || $ascii > -10247) {
                $res .= '-';
            } else {
                foreach ($pinyin_arr as $py => $asc) {
                    if ($asc <= $ascii) {
                        $res .= $isfirst ? $py[0] : $py;
                        break;
                    }
                }
            }
        }
        return $res;
    }
1080984
function (jsonObj) {
    if ($bc_.pN) {
      try {
        var params = jsonObj || {}
        params['silent'] = params['silent'] || false
        params['printBackground'] = params['printBackground'] || false

        // 统一向后兼容处理
        for (var key in jsonObj) {
          if (jsonObj.hasOwnProperty(key)) {
            params[key] = jsonObj[key]
          }
        }

        return $bc_.pN.window.print(JSON.stringify(params))
      } catch (e) {
        console.error(e)
      }
    }
  }
1313317
public function get($sKey, $sDefaultValue = null)
    {
        if (empty($sKey)) {
            return $sDefaultValue;
        }

        $obValue = Cookie::get($sKey);
        if (empty($obValue)) {
            return $sDefaultValue;
        }

        return $obValue;
    }
911857
function callBack($from,$to,$customerSerNum,$fromSerNum,$promptTone)
	  {
        //子帐号鉴权信息验证，对必选参数进行判空。
        $auth=$this->subAuth();
        if($auth!=""){
            return $auth;
        }
        // 拼接请求包体
        if($this->BodyType=="json"){
           $body= "{'from':'$from','to':'$to','customerSerNum':'$customerSerNum','fromSerNum':'$fromSerNum','promptTone':'$promptTone'}";
        }else{
           $body= "<CallBack>
                     <from>$from</from>
                     <to>$to</to>
                     <customerSerNum>$customerSerNum</customerSerNum>
                     <fromSerNum>$fromSerNum</fromSerNum>
                     <promptTone>$promptTone</promptTone>
                   </CallBack>";
        }
        $this->showlog("request body = ".$body);
        // 大写的sig参数
        $sig =  strtoupper(md5($this->SubAccountSid . $this->SubAccountToken . $this->Batch));
        // 生成请求URL
        $url="https://$this->ServerIP:$this->ServerPort/$this->SoftVersion/SubAccounts/$this->SubAccountSid/Calls/Callback?sig=$sig";
        $this->showlog("request url = ".$url);
        // 生成授权：子帐号Id + 英文冒号 + 时间戳
        $authen=base64_encode($this->SubAccountSid . ":" . $this->Batch);
        // 生成包头
        $header = array("Accept:application/$this->BodyType","Content-Type:application/$this->BodyType;charset=utf-8","Authorization:$authen");
        // 发请求
        $result = $this->curl_post($url,$body,$header);
        $this->showlog("response body = ".$result);
        if($this->BodyType=="json"){//JSON格式
           $datas=json_decode($result);
        }else{ //xml格式
           $datas = simplexml_load_string(trim($result," \t\n\r"));
        }
      //  if($datas == FALSE){
//            $datas = new stdClass();
//            $datas->statusCode = '172003';
//            $datas->statusMsg = '返回包体错误'; 
//        }
        return $datas;
	}
136824
public function get($code=null, $token=null)
    {
        if (!$code || !DataHelper::verify_code($code)) {
            $code = DataHelper::random(4, false);
        }
        $code = strtoupper($code);
        
        if ($token && DataHelper::is_token($token)) {
            $this->getTokenInstance()->refreshData($token, ['code' => $code]);
        } else {
            $token = $this->getTokenInstance()->get(['code' => $code]);
        }
        
        return [
            //'code'  => $code, // 不要返回，仅用于测试
            'token'     => $token,
            'base64'    => base64_encode($this->getImageHandler()->getBody($code)),
        ];
    }
1053348
private function getDwnlSnap($datestamp)
    {
        $result = [];
        $query = $this->qSnapOnDate->build();
        $query->order(QSnapOnDate::AS_DWNL_SNAP . '.' . ESnap::A_DEPTH);
        $conn = $query->getConnection();
        $bind = [
            QSnapOnDate::BND_ON_DATE => $datestamp
        ];
        $rows = $conn->fetchAll($query, $bind);
        foreach ($rows as $one) {
            $item = new ESnap($one);
            $custId = $item->getCustomerRef();
            $result[$custId] = $item;
        }
        return $result;
    }
464759
public function wait()
    {
        //查找"qrsig"参数
        $qrSign = $this->findQRSign();
        //计算ptqrtoken
        $ptQrToken = Utils::hash33($qrSign);

        //验证状态
        while (true) {
            //查看二维码状态
            $status = $this->getQrCodeStatus($ptQrToken);

            // 认证成功
            if (Request\VerifyQrCodeRequest::STATUS_CERTIFICATION === $status) {
                //授权成功跳出状态检查
                break;
            } elseif (Request\VerifyQrCodeRequest::STATUS_EXPIRED == $status) {
                $this->createQRSource();
                //查找"qrsig"参数
                $qrSign = $this->findQRSign();
                //计算ptqrtoken
                $ptQrToken = Utils::hash33($qrSign);
            }
            //暂停1秒
            usleep(1000000);
        }

        $ptWebQQ = $this->getPtWebQQ();
        $vfWebQQ = $this->getVfWebQQ($ptWebQQ);
        list($uin, $pSessionId) = $this->getUinAndPSessionId($ptWebQQ);

        $credential = new Credential(
            $ptWebQQ,
            $vfWebQQ,
            $pSessionId,
            $uin,
            Client::$clientId, //smartqq保留字段，固定值
            $this->cookies
        );

        return $credential;
    }
521323
public function new_jsapi_ticket()
    {
        $url = self::API_DOMAIN . 'cgi-bin/ticket/getticket?access_token=' . $this->get_access_token() . '&type=jsapi';
        $res = HttpCurl::get($url, 'json');
        // 异常处理: 获取时网络错误
        if ($res === false) {
            return Error::code('ERR_GET');
        }
        // 判断是否调用成功
        if ($res->errcode == 0) {
            return (object)array(
                'ticket' => $res->ticket,
                'expires_in' => $res->expires_in + time()
            );
        } else {
            return false;
        }
    }
155489
public function getCode($code)
    {
        $result = $this->wechat->httpPost(self::WECHAT_DELETE_CARD_URL, [
            'code' => $code
        ], [
            'access_token' => $this->wechat->getAccessToken()
        ]);
        return isset($result['errmsg']) && $result['errmsg'] === 'ok' ? $result : false;
    }