PHP code example of fengyikang88 / fykeasychat

1. Go to this page and download the library: Download fengyikang88/fykeasychat 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/ */

    

fengyikang88 / fykeasychat example snippets



use FykEasyChat\WechatQrcode;

    /**
     * Generate Mini Program QR Code
     */
    public function QrCode()
    {
        $config =[
            'app_id'  => '',// 小程序app_id
            'secret'  => '', //小程序app_secret
        ];
        $mod = new WechatQrcode($config);
        $base64_image =  $mod->miniCircularImg('pages/index/index?qrcode=helloworld');
   
        return $base64_image;
        
    }
 


use FykEasyChat\HealthOpen;


    //微信电子健康卡开放平台账号
    private $config = [
        'appId' => '',//开发者ID(AppID)
        'appSecret' => '',//开发者密码(AppSecret)
        'hospitalId' => '', //医院ID
        'paTid' => '',
    ];
        
    /**
     * 获取token
     * @return array
     * @author fyk
     * Time 2021/1/18
     */
    public function getAppToken()
    {
        $wechat = new HealthOpen($this->config);
        try {
            $res = $wechat->getAppToken();
            $result = json_decode($res,true);
            if($result['commonOut']['resultCode'] == 0){
                $ret['requestId'] = $result['commonOut']['requestId'];
                $ret['appToken'] = $result['rsp']['appToken'];
                //存入缓存方便调取
                $redis = new RedisCache();
                $redis->set('HealthAppToken',$ret['appToken'],7100);
                return $ret['appToken'];
            }else{
                throw new BusinessException(ErrorCode::Health_SERVER_ERROR, $result['commonOut']['errMsg']);
            }
        } catch (\Exception $e) {
            throw new BusinessException($e->getMessage());
        }

    }