Giter Club home page Giter Club logo

weworkapi's Introduction

About

elutiger/weworkapiweworkapi_php (official lib of wework api https://work.weixin.qq.com/api/doc) 在laravel下的安装包,支持laravel5.5以上版本测试使用。本库仅做示范用,并不保证完全无bug;另外,作者会不定期更新本库,但不保证与官方API接口文档同步,因此一切以官方文档为准。

Install

step 1: $ composer require elutiger/weworkapi-for-laravel5 "dev-master"

step 2: $ php artisan vendor:publish --provider "Elutiger\Weworkapi\WeworkapiServiceProvider"

change the config in the generated file "config/weworkapi.php"

// 请将下面参数改为自己的企业相关参数再进行测试

return array (
// 企业的id,在管理端->"我的企业" 可以看到
"CORP_ID"               => "ww4b7f2b843202****",

// "通讯录同步"应用的secret, 开启api接口同步后,可以在管理端->"通讯录同步"看到
"CONTACT_SYNC_SECRET"   => "RGVi7yFu5BzM00ijo20CR2SRYJKYQoGrAHyr_GSrT58",

// 自建应用的id及secret, 在管理端 -> 企业应用 -> 自建应用, 点进相应应用可以看到
"AGENTS" => [
    "WEWORK_APP_1" => [
        "APP_ID"        => 1000002,
        "APP_SECRET"    => "Q0yAyQhZ2pXt12pcMRq36g1dbrEci028GTVIDNyKqLg",  
        "APP_NAME"      => "应用消息",
        "APP_IDENTITY"  => "WEWORK_APP_1"   
    ],
   
], 

// 打卡应用的 id 及secrete, 在管理端 -> 企业应用 -> 基础应用 -> 打卡,
// 点进去,有个"api"按钮,点开后,会看到
"CHECKIN_APP_ID"        => 3010011,
"CHECKIN_APP_SECRET"    => "UiaHraIs_CULvovHDyiaBjODrfsWzXGmZtWcPr8JIbA",

// 审批应用的 id 及secrete, 在管理端 -> 企业应用 -> 基础应用 -> 审批,
// 点进去,有个"api"按钮,点开后,会看到
"APPROVAL_APP_ID"       => 3010040,
"APPROVAL_APP_SECRET"   => "R79l0DKnrALsIK5J_DcjU7TzP-ipCjFKYOzBs53IC80",

);

step 3: add facade alias to the config file "config/app.php", in the case add code lines to the aliases array like below

'Weworkapi' => Elutiger\Weworkapi\Facades\Weworkapi::class,

Usage

use Log;
use Weworkapi;
use Elutiger\Weworkapi\Message;
use Elutiger\Weworkapi\NewsMessageContent;
use Elutiger\Weworkapi\NewsArticle;

////////////////////////////////////////////////////////////

$agent = config('weworkapi.AGENTS.WEWORK_APP_1');

Weworkapi::init(config('weworkapi.CORP_ID'), $agent['APP_SECRET']);
	 
    try { 
        
            $message = new Message();
            {
                $message->sendToAll = false;
                $message->touser = ['userid'];
                $message->toparty = [];
                $message->totag = [];
                $message->agentid = $agent['APP_ID'];
                $message->safe = 0;

                $message->messageContent = new NewsMessageContent(
                    array( 
                         
                        new NewsArticle(
                            $title = $event->notice_data->title, 
                            $description = $event->notice_data->description, 
                            $url = $event->notice_data->url, 
                            $picurl = "http://res.mail.qq.com/node/ww/wwopenmng/images/independent/doc/test_pic_msg1.png", 
                            $btntxt = $event->notice_data->btntxt
                        )
                    )
                );

                /*$message->messageContent = new \TextCardMessageContent(
                        $title = $event->notice_data->title, 
                        $description = $event->notice_data->description, 
                        $url = $event->notice_data->url, 
                        $btntxt = $event->notice_data->btntxt
                );*/
            }
            $invalidUserIdList = null;
            $invalidPartyIdList = null;
            $invalidTagIdList = null;

            Weworkapi::MessageSend($message, $invalidUserIdList, $invalidPartyIdList, $invalidTagIdList);
            
            
        } catch (Exception $e) { 
            Log::info($e->getMessage());
        }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.