PHP code example of chenall / phalapi-weixin

1. Go to this page and download the library: Download chenall/phalapi-weixin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

chenall / phalapi-weixin example snippets


new \PhalApi\WeiXin\Lite(服务名);

return array(
    /**
     * 扩展类库 - 微信公众号配置
     * 注: 具体配置参数请参考 https://www.easywechat.com/docs
     */
    'corp_id' => 'xxxxxxxxxxxxxxxxx',

    'agent_id' => 100020, // 如果有 agend_id 则填写
    'secret'   => 'xxxxxxxxxx',

    // 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
    'response_type' => 'array',

    'log' => [
        'level' => 'debug',
        'file' => __DIR__.'/wechat.log',
    ],
);

//企业微信
$di->wxWork = function(){
    $weixin = new \PhalApi\WeiXin\Lite('Work');
    return $weixin->wxApp();
};
//公众号
$di->officialAccount = function(){
    $weixin = new \PhalApi\WeiXin\Lite('officialAccount');
    return $weixin->wxApp();
};

//./Public/WeiXin.php
/**
 * 统一访问入口
 */
r->response('\\WeiXin\\Work\\Server');

//可以直接扩展\PhalApi\WeiXin\Server,也可以完全自己实现
class Server extends \PhalApi\WeiXin\Server {
    public function text($message){
        .....
        //消息类型 可以返回各种消息类型,比如图片,文本等,具体的使用方法参考说明文档
        return 要返回给消息发送者的信息;
    }
}