微擎常用函數集合

微擎常用不需要加載自帶函數

寫入cookie 過期時間秒,0表示跟隨瀏覽器,false,不允許js讀取

isetcookie($key$value$expire = 0, $httponly = false) 

獲取客戶端IP

$ip =  getip();

隨機字符串,6是長度,1爲是否數字,

random(6,true);

獲取表明

tablename('account')

生成如下地址 :   ./index.php?i=5&c=site&a=entry&do=rank&m=yoby_test&op=del,true不帶微信拼接字符,第二個true表示添加域名

$url  = murl('site/entry/rank', ['m'=>'yoby_test','op'=>'del'], 1,1);

$url  =  wurl('site/entry/rank',['m'=>'yoby_test']);

一般微信端

murl('entry', ['m'=>'yoby_diyform','do'=>'index','rid'=>$item['rid']], 1,1)

分頁

pagination($total$pageIndex$pageSize = 15);

返回媒體或圖片路徑

tomedia($src)

查找字符串

strexists('helloworld''h'); 

截取字符串

cutstr($string,$length, TRUE,'utf-8');

計算字符串長度,中英文都爲1

istrlen('hello-微擎');

字符串加密或解密,默認解密,ENCODE加密,key祕鑰,0過期時間

authcode($string$operation 'DECODE'$key ''$expiry = 0)

emoji_unicode_decode()emoji_unicode_encode 解碼emoji

get_first_pinyin($str)拼音首字母

ihtml_entity_decode 顯示html

array2xml xml2array xml數組互換

web默認加載,微信端也有以下函數

第二個參數爲空,不跳轉,warning警告,error錯誤,info提示,ajax

message('成功', referer(), 'success');

ajax 返回 {"message":"\u6210\u529f","redirect":"","type":"ajax"}

模板加載

template('common/template');

iajax(code,message,redirect);參數2支持數組或字符串

itoast("配置保存成功", referer(), 'success');

文件操作函數

load()->func('file');

file_copy(IA_ROOT . '/web', IA_ROOT . '/data'array('php')) 文件複製 過濾php 

file_delete('test.png');

file_image_crop(IA_ROOT . '/test.png', IA_ROOT . '/test2.png', 50, 50); 剪切

file_image_thumb(IA_ROOT . '/test.png', IA_ROOT . '/test2.png', 500); 生成縮率圖 最後是寬

file_move(IA_ROOT . '/test.log', IA_ROOT . '/web/test.log');文件移動

file_upload($_FILE['test'], 'image''test.png'); 上傳

file_write(IA_ROOT . '/test.log''hello-world');文件寫入

mkdirs(IA_ROOT . '/web/hello/world/example');創建目錄

file_remote_delete遠程刪除

寫入遠程

$filename ="images/$weid/yoby_tougao_".$snid.'.jpg';

 file_write($filename$data);

        if (!empty($_W['setting']['remote']['type'])) { // 判斷系統是否開啓了遠程附件

            $remotestatus = file_remote_upload($filename); //上傳圖片到遠程

            if (is_error($remotestatus)) {

                message('遠程附件上傳失敗,請檢查配置並重新上傳') ;

}

        }

http操作函數

load()->func('communication');

$result = ihttp_get('http://x.com')['content'];

文件上傳@+絕對路徑

$result = ihttp_post('https://www.baidu.com'array('username' => 'we7'));

高級請求,第三個參數附加傳入

ihttp_request($url$post ''$extra array(), $timeout = 60)

記錄日誌

load()->func('logging');

logging_run('記錄字符串日誌數據');

logging_run([1,2,3]);

用戶中心

load()->model('mc');

檢測是否登錄,沒登陸跳到登陸

checkauth();用於微信端 checklogin()用於web

openid轉換uid

$uid $_W['member']['uid'];

  Array

(

    [uid] => 10128

    [realname] => 用戶暱稱

    [mobile] => 手機號碼

    [email] => 郵箱

    [groupid] => 用戶組ID

    [groupname] => 用戶組名稱

    [credit1] => 積分

    [credit2] => 餘額

    [credit3] => 其它積分

    [credit4] => 其它積分

    [credit5] => 其它積分

    [credit6] => 其它積分

)

$uid =  mc_openid2uid($openid);

$openid = mc_uid2openid($uid);

mc_credit_update($uid,'credit2', -10,[$uid,'測試減少10積分']);//增減積分

$num =  mc_credit_fetch($uid,['credit2']);//查詢積分

積分通知

mc_notice_credit1($openid$uid, 10, '充值積分到賬10分'$url 'http://w.cn'$remark '謝謝惠顧,點擊查看詳情');

彈出填寫信息

mc_require($openid,['realname''mobile']);

更新填寫信息

mc_update($openid,['email' => '[email protected]']);

查詢用戶信息uid,返回字段

mc_fansinfo($uidoropenid)

Oauth獲取用戶信息

mc_oauth_userinfo($acid)

通過openid獲取

mc_oauth_fans($openid)

查詢用戶信息

mc_fetch($uid/openid,[])返回字段

uid,mobile,credit1積分,credit2餘額,realname,nickname,avatar,gender 1男2女,residecity市

自定義函數

微信中做了base64的加密字符串解密,解密之前不需要base64解密

openssl_decrypt($wechat_data['req_info'], "AES-256-ECB", md5('appid'));

serialize unserialize 序列化

extract($arr);compact('a','b','c','d','i');解碼成字符串

explode('-','1-2-3-4');//分割成數組

implode('-',$arr);//轉換成字符串

mb_convert_encoding('李太白',"utf-8",'auto');自動轉換成uft8

foreach($list as &$row){

處理數據

}

unset($row);

支付幾種返回

$wechat = uni_setting(1, array('payment'));

借用返回

Array

(

    [payment] => Array

        (

            [credit] => Array

                (

                    [switch] => 

                )

            [alipay] => Array

                (

                    [switch] => 

                    [account] => 

                    [partner] => 

                    [secret] => 

                )

            [wechat] => Array

                (

                    [switch] => 2

                    [account] => 1

                    [signkey] => 

                    [partner] => 

                    [key] => 

                    [borrow] => 2

                )

            [delivery] => Array

                (

                    [switch] => 

                )

        )

)

本身返回

Array

(

    [payment] => Array

        (

            [wechat] => Array

                (

                    [switch] => 1

                    [version] => 2

                    [apikey] => J8BNZ88rR8hhHH9Z7bqhbB57HbQOp3F9

                    [mchid] => 1493418902

                    [account] => 2

                    [signkey] => J8BNZ88rR8hhHH9Z7bqhbB57HbQOp3F9

                )

        )

)

非支付id返回

Array

(

    [payment] => Array

        (

            [wechat] => Array

                (

                    [switch] => 2

                    [borrow] => 2

                    [account] => 3

                    [signkey] => 

                )

        )

)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章