Giter VIP home page Giter VIP logo

wxmsg's Introduction

An editor for WeChat Custom Service Message.

This is a laravel-admin extension that can edit WeChat Custom Service Message with form input.

Screenshot

Installation

First, install dependencies:

composer require yisonli/wxmsg

Usage

Use it in the form form:

$form->wxmsg('content');

Advance Usage :

  • function relateTo : Diy message type field.
  • function selectMedia : Query mediaID list by ajax api.
$form->select('app_id', '公众号')->options($app_list)->rules('required');
$form->select('msgtype', '回复消息类型')->options([
        'text' => '文本',
        'image' => '图片',
        'news' => '图文',
        'link' => '图文(小程序)',
        'miniprogrampage' => '小程序卡片',
    ])->rules('required');
$form->wxmsg('content', '')->relateTo('msgtype', 'app_id')->selectMedia('/wechat/reply/medias');

While using selectMedia, you must add the Controller Function for /wechat/reply/medias first.

  1. Add controller function:
public function medias(Request $request)
{
    $app_id = $request->get('a');
    $name = $request->get('q');
    $type = $request->get('t');

    $result = WechatMedia::where('app_id', '=', $app_id)
        ->where('type', '=', $type)
        ->where('name', 'like', "%$name%")
        ->paginate(null, ['media_id', 'name', 'url']);

    foreach ($result as $key => $value) {
        $temp = [
            'id' => $value['media_id'],
            'text' => '<img style="max-width:40px;max-height:40px;" src="'.$value['url'].'" /> ' . $value['name'],
        ];
        $result[$key] = $temp;
    }

    return $result;
}
  1. Add api to route file:
$router->get('/wechat/reply/medias', 'Wechat\ReplyController@medias');

Support Message Types

  • text
  • image
  • news
  • link
  • miniprogrampage

To be continue

  • Support other message types. (exp: video, music, msgmenu...)
  • Beautify the operation interface.

License

Licensed under The MIT License.

About Me

name: yison.li
blog: http://yyeer.com
github: https://github.com/yisonli

wxmsg's People

Contributors

yisonli avatar

Stargazers

嘻嘻生活 avatar jay avatar Kend avatar  avatar  avatar captain avatar  avatar  avatar

Watchers

James Cloos avatar  avatar

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.