联系我们:416326801#qq.com(#改成@)

Latest from the blog

Discuz修改附件图标

标签: PHP Discuz

Discuz有一部分不常用的附件图标是问号,下面操作步骤可以自定义Discuz附件图标。

1、准备图标,一般是正方形的png或gif文件,建议大小64*64或128*128。

2、上传图标到目录:/static/image/filetype,修改为自定义名字,例如mobi.png

3、修改源码文件:/source/function/function_attachment.php

4、修改部分参考示例代码的第17-20、36-31行

附件图标.png

<?php
static $attachicons = array(
    1 => 'unknown.gif',
    2 => 'binary.gif',
    3 => 'zip.gif',
    4 => 'rar.gif',
    5 => 'msoffice.gif',
    6 => 'text.gif',
    7 => 'html.gif',
    8 => 'real.gif',
    9 => 'av.gif',
    10 => 'flash.gif',
    11 => 'image.gif',
    12 => 'pdf.gif',
    13 => 'torrent.gif',
    14 => 'book.png',
    15 => 'ebook.png',
    16 => 'mobi.png',
    17 => 'azw3.png',
    18 => 'epub.png',
);

if( is_numeric($type) ) {
    $typeid = $type;
} else {
    if( preg_match("/epub|^epub\t/", $type) ) {
        $typeid = 18;
    } elseif( preg_match("/azw3|^azw3\t/", $type) ) {
        $typeid = 17;
    } elseif( preg_match("/mobi|^mobi\t/", $type) ) {
        $typeid = 16;
    } elseif( preg_match("/bittorrent|^torrent\t/", $type) ) {
        $typeid = 13;
    } elseif( preg_match("/pdf|^pdf\t/", $type) ) {
        $typeid = 12;
    } elseif( preg_match("/image|^(jpg|gif|png|bmp)\t/", $type) ) {
        $typeid = 11;
    } elseif( preg_match("/flash|^(swf|fla|flv|swi)\t/", $type) ) {
        $typeid = 10;
    } elseif( preg_match("/audio|video|^(wav|mid|mp3|m3u|wma|asf|asx|vqf|mpg|mpeg|avi|wmv)\t/", $type) ) {
        $typeid = 9;
    } elseif( preg_match("/real|^(ra|rm|rv)\t/", $type) ) {
        $typeid = 8;
    } elseif( preg_match("/htm|^(php|js|pl|cgi|asp)\t/", $type) ) {
        $typeid = 7;
    } elseif( preg_match("/text|^(txt|rtf|wri|chm)\t/", $type) ) {
        $typeid = 6;
    } elseif( preg_match("/word|powerpoint|^(doc|ppt)\t/", $type) ) {
        $typeid = 5;
    } elseif( preg_match("/^rar\t/", $type) ) {
        $typeid = 4;
    } elseif( preg_match("/compressed|^(zip|arj|arc|cab|lzh|lha|tar|gz)\t/", $type) ) {
        $typeid = 3;
    } elseif( preg_match("/octet-stream|^(exe|com|bat|dll)\t/", $type) ) {
        $typeid = 2;
    } elseif( $type ) {
        $typeid = 1;
    } else {
        $typeid = 0;
    }
}
?>

PHP提取文章第一张图片

标签: PHP

代码未测试...
$pattern = "/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png|\.jpeg]))[\'|\"].*?[\/]?>/";
preg_match($pattern, $content, $matchContent);
//preg_match_all($pattern, $content, $matchContent);
print_r($matchContent);
exit();

代码2

$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $content, $matches);
 
// 获取文章中第一张图片的路径并输出
$first_img = $matches[1][0];

// 如果文章无图片,获取自定义图片并显示
if(empty($first_img)){
$first_img = "/images/default.jpg";
}


微信支付退款结果通知解密

标签: PHP Weixin wxpay

微信支付退款结果通知解密步骤如下: 

第一步,对商户密钥key进行MD5加密,得到32位小写加密串StringA

key设置路径:微信商户平台(pay.weixin.qq.com)-->账户设置-->API安全-->密钥设置 

第二步,使用StringA作为key,对参数加密串进行AES-256(ECB模式,PKCS7Padding)解密,得到加密前参数。


第一步很好理解, 第二步微信并没有给出demo, 经测试可用的PHP代码如下

注意:示例函数的$key不是商户秘钥,需要事先进行MD5加密

明文=refund_decrypt(密文,MD5(商户秘钥));

$refund_xml_string = refund_decrypt($weixin_post_string, md5($weixin_key));

function refund_decrypt($str, $key) {
        $str = base64_decode($str);
        $str = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $str, MCRYPT_MODE_ECB);
        $block = mcrypt_get_block_size('rijndael_128', 'ecb');
        $pad = ord($str[($len = strlen($str)) - 1]);
        $len = strlen($str);
        $pad = ord($str[$len - 1]);
        return substr($str, 0, strlen($str) - $pad);
}

解密结果示例

解密后:

<root>
<out_refund_no><![CDATA[R4001312001201707262674894706_4]]></out_refund_no>
<out_trade_no><![CDATA[201707260201501501005710775]]></out_trade_no>
<refund_account><![CDATA[REFUND_SOURCE_UNSETTLED_FUNDS]]></refund_account>
<refund_fee><![CDATA[15]]></refund_fee>
<refund_id><![CDATA[50000203702017072601461713166]]></refund_id>
<refund_recv_accout><![CDATA[用户零钱]]></refund_recv_accout>
<refund_request_source><![CDATA[API]]></refund_request_source>
<refund_status><![CDATA[SUCCESS]]></refund_status>
<settlement_refund_fee><![CDATA[15]]></settlement_refund_fee>
<settlement_total_fee><![CDATA[100]]></settlement_total_fee>
<success_time><![CDATA[2017-07-26 02:45:49]]></success_time>
<total_fee><![CDATA[100]]></total_fee>
<transaction_id><![CDATA[4001312001201707262674894706]]></transaction_id>
</root>

退款结果图:

微信支付退款测试.jpg

1 2 3 4 5 6 7 ... Next »... Last »