微信公众号开发代码参考

<?php

namespace backend\modules\api\controllers;

use common\models\SmsReport;
use common\models\Aes;
use common\models\Counter;
use common\models\Phone;
use common\models\City;
use common\models\oss\oss;
use common\models\PersonLooking;
use Yii;
use yii\rest\Controller;
use backend\modules\api\common\lib\Helper;
use backend\modules\api\models\User;
use backend\modules\api\models\FreeDelivery;
use backend\modules\api\models\Register;
use backend\modules\api\common\lib\HttpUploadFile;
use yii\base\Object;
use backend\modules\api\models\Login;
use backend\modules\api\models\Equipment;
use backend\modules\api\models\Active;
use backend\modules\api\models\Order;
use backend\modules\api\models\AdminDelivery;
use backend\modules\api\models\ShopActive;
use backend\modules\api\models\Abnormal;
use backend\modules\api\models\WxUser;

header(‘Access-Control-Allow-origin:*‘);
header(‘Access-Control-Allow-Credentials:true‘);
header(‘Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS‘);
header(‘Access-Control-Allow-Headers:Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With‘);
header(‘Content-Type: text/html; charset=utf-8‘);

class WechatController extends Controller {
    public function actionIndex(){
        $nonce = Yii::$app->request->get(‘nonce‘);
        $token = ‘adshare‘;
        $timestamp = Yii::$app->request->get(‘timestamp‘);
        $echostr = Yii::$app->request->get(‘echostr‘);
        $signature = Yii::$app->request->get(‘signature‘);
        $array = array();
        $array = array($nonce,$timestamp,$token);
        sort($array);
        $str = sha1(implode($array));
        if($str == $signature && $echostr){
            return $echostr;
        }else{
            self::actionMessage();
        }
    }

    public function actionGetUserInfo($token,$openid){
        $url = ‘https://api.weixin.qq.com/cgi-bin/user/info?access_token=‘.$token.‘&openid=‘.$openid.‘&lang=zh_CN‘;

        $res= self::actionCurlRequest($url);
        return json_decode($res,true);
    }

    public function actionMessage(){
        $postArr = $GLOBALS[‘HTTP_RAW_POST_DATA‘];
        $postObj = simplexml_load_string($postArr);
        if(strtolower($postObj->MsgType) == ‘event‘){
            if(strtolower($postObj->Event) == ‘subscribe‘){

                $UserInfo = WxUser::find()->where([‘openid‘=>$postObj->FromUserName])->one();
                if(!empty($UserInfo)){
                    $UserInfo->is_subscribe = 1;
                    $model->save(false);
                }else{
                    //获取用户信息
                    $token = self::actionGetToken();
                    $res = self::actionGetUserInfo($token,$postObj->FromUserName);
                    $model = new WxUser();
                    $model->openid = $res[‘openid‘];
                    $model->unionid = $res[‘unionid‘];
                    $model->sex = $res[‘sex‘];
                    $model->imgs = $res[‘headimgurl‘];
                    $model->username = $res[‘nickname‘];
                    $model->create_time = time();
                    $model->login_time = time();
                    $model->login_ip = $_SERVER["REMOTE_ADDR"];
                    $model->create_ip = $_SERVER["REMOTE_ADDR"];
                    //$model->lng = $Longitude;
                    //$model->lat = $Latitude;
                    $model->save(false);
                }

                $toUser = $postObj->FromUserName;//用户的openid
                $fromUser = $postObj->ToUserName;
                $time = time();
                $Msgtype = ‘news‘;
                $arr = array(
                    array(
                        ‘Title‘=>‘欢迎关注AD共享‘,
                        ‘Description‘=>‘这是一个属于互联网传媒的时代‘,
                        ‘PicUrl‘=>‘http://fx.peita.net/adShared/img/icon/banner.png‘,
                        ‘Url‘=>‘http://fx.peita.net/adShared/pages/home.html‘
                    )
                );

                $template = "<xml>
                            <ToUserName><![CDATA[%s]]></ToUserName>
                            <FromUserName><![CDATA[%s]]></FromUserName>
                            <CreateTime>%s</CreateTime>
                            <MsgType><![CDATA[%s]]></MsgType>
                            <ArticleCount>".count($arr)."</ArticleCount>
                            <Articles>";

                foreach($arr as $key=>$v){
                    $template .="<item>
                            <Title><![CDATA[".$v[‘Title‘]."]]></Title>
                            <Description><![CDATA[".$v[‘Description‘]."]]></Description>
                            <PicUrl><![CDATA[".$v[‘PicUrl‘]."]]></PicUrl>
                            <Url><![CDATA[".$v[‘Url‘]."]]></Url>
                            </item>";
                }

                $template .="</Articles>
                            </xml>";
                $info = sprintf($template,$toUser,$fromUser,$time,$Msgtype);
                echo $info;

                /*$toUser = $postObj->FromUserName;
                $fromUser = $postObj->ToUserName;
                $time = time();
                $Msgtype = ‘text‘;
                //$Content = $postObj->FromUserName;
                $Content = ‘欢迎关注AD共享公众号‘;
                $template = "<xml>
                            <ToUserName><![CDATA[%s]]></ToUserName>
                            <FromUserName><![CDATA[%s]]></FromUserName>
                            <CreateTime>%s</CreateTime>
                            <MsgType><![CDATA[%s]]></MsgType>
                            <Content><![CDATA[%s]]></Content>
                            </xml>";
                $info = sprintf($template,$toUser,$fromUser,$time,$Msgtype,$Content);
                echo $info;*/
            }

            if($postObj->Event == ‘LOCATION‘){
                $model = WxUser::find()->where([‘openid‘=>$postObj->FromUserName])->one();
                $model->lng = $postObj->Longitude;
                $model->lat = $postObj->Latitude;
                $model->save(false);

                /*$toUser = $postObj->FromUserName;
                $fromUser = $postObj->ToUserName;
                $time = time();
                $Msgtype = ‘text‘;
                //$Content = $postObj->FromUserName;
                $Content = ‘已经上报您的地理位置信息‘;
                $template = "<xml>
                            <ToUserName><![CDATA[%s]]></ToUserName>
                            <FromUserName><![CDATA[%s]]></FromUserName>
                            <CreateTime>%s</CreateTime>
                            <MsgType><![CDATA[%s]]></MsgType>
                            <Content><![CDATA[%s]]></Content>
                            </xml>";
                $info = sprintf($template,$toUser,$fromUser,$time,$Msgtype,$Content);
                echo $info;*/
            }

            if(strtolower($postObj->Event) == ‘unsubscribe‘){
                $model = WxUser::find()->where([‘openid‘=>$postObj->FromUserName])->one();
                if(!empty($model)){
                    $model->is_subscribe = 2;
                    $model->save(false);
                }

            }

            if($postObj->Event == ‘CLICK‘ && $postObj->EventKey == ‘balance‘){
                $data = WxUser::find()->select(‘openid,username,all_money‘)->where([‘openid‘=>$postObj->FromUserName])->one();

                if(empty($data)){
                    $toUser = $postObj->FromUserName;
                    $fromUser = $postObj->ToUserName;
                    $time = time();
                    $Msgtype = ‘text‘;
                    //$Content = $postObj->FromUserName;
                    $Content = ‘未获取到您的个人信息,您可以试着重新关注一下‘;
                    $template = "<xml>
                                <ToUserName><![CDATA[%s]]></ToUserName>
                                <FromUserName><![CDATA[%s]]></FromUserName>
                                <CreateTime>%s</CreateTime>
                                <MsgType><![CDATA[%s]]></MsgType>
                                <Content><![CDATA[%s]]></Content>
                                </xml>";
                    $info = sprintf($template,$toUser,$fromUser,$time,$Msgtype,$Content);
                    echo $info;
                    die;
                }

                if(!empty(Yii::$app->session[‘wx_token‘])){
                    $token = Yii::$app->session[‘wx_token‘];
                }else{
                    unset(Yii::$app->session[‘wx_token‘]);
                    $token = self::actionGetToken();
                }

                $toUser = $data->openid;
                $url = ‘https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=‘.$token;
                $sj = date(‘Y-m-d H:i:s‘,time());
                $money = $data->all_money.‘元‘;
                $message = [
                    ‘touser‘=>$toUser,
                    ‘template_id‘=>‘egyvsRQoBVnOwiyNLk94yhNkhNSDCWKA68GwDf_1QZg‘,
                    ‘data‘=>[
                        ‘first‘=>[‘value‘=>‘您好,账户余额信息如下:‘,‘color‘=>‘#FF0000‘],
                        ‘keyword1‘=>[‘value‘=>$data->username,‘color‘=>‘#173177‘],
                        ‘keyword2‘=>[‘value‘=>$money,‘color‘=>‘#173177‘],
                        ‘keyword3‘=>[‘value‘=>$sj,‘color‘=>‘#173177‘],
                        ‘remark‘=>[‘value‘=>‘如有任何疑问请登录会员系统联系在线客服‘,‘color‘=>‘#173177‘]
                    ]
                ];

                $data2 = json_encode($message);
                $res = self::actionCurlRequest($url,$data2);
                return $res;

            }

            if($postObj->Event == ‘VIEW‘ && $postObj->EventKey == ‘http://fx.peita.net/adShared/pages/home.html‘){
                $model = WxUser::find()->where([‘openid‘=>$postObj->FromUserName])->one();
                if(!empty($model)){
                    $model->login_ip = $_SERVER["REMOTE_ADDR"];
                    $model->save(false);
                }

            }

        }

    }

    //发送模版消息
    public function actionPushMessage($openid,$all_money,$username){

        //$wxinfo = WxUser::find()->select(‘openid,username,all_money‘)->where([‘<‘, ‘all_money‘, 10])->asArray()->all();

        if(!empty(Yii::$app->session[‘wx_token‘])){
            $token = Yii::$app->session[‘wx_token‘];
        }else{
            unset(Yii::$app->session[‘wx_token‘]);
            $token = self::actionGetToken();
        }

        $url = ‘https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=‘.$token;
        $time = date(‘Y-m-d H:i:s‘,time());
        $cz_url = ‘http://www.peita.net‘;
        $message = [
            ‘touser‘=>$openid,
            ‘template_id‘=>‘SudqvwsNYy4AFqBO4_KaWklYlhrc69c74jiAF3VBoCU‘,
            ‘url‘=>$cz_url,
            ‘data‘=>[
                ‘first‘=>[‘value‘=>‘您好,您的账户余额不足。请尽快充值,以免影响您的使用。‘,‘color‘=>‘#FF0000‘],
                ‘keyword1‘=>[‘value‘=>$username,‘color‘=>‘#173177‘],
                ‘keyword2‘=>[‘value‘=>$all_money.‘元‘,‘color‘=>‘#173177‘],
                ‘keyword3‘=>[‘value‘=>$cz_url,‘color‘=>‘#173177‘],
                ‘keyword4‘=>[‘value‘=>$time,‘color‘=>‘#173177‘],
                ‘remark‘=>[‘value‘=>‘如有任何疑问请登录会员系统联系在线客服‘,‘color‘=>‘#173177‘]
            ]
        ];

        $data = json_encode($message);
        $res = self::actionCurlRequest($url,$data);

    }

    //充值成功模板
    public function actionRechargePushMessage(){

        if(!empty(Yii::$app->session[‘wx_token‘])){
            $token = Yii::$app->session[‘wx_token‘];
        }else{
            unset(Yii::$app->session[‘wx_token‘]);
            $token = self::actionGetToken();
        }

        $url = ‘https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=‘.$token;
        $time = date(‘Y-m-d H:i:s‘,time());
        $message = [
            ‘touser‘=>‘oH9aS1fyOd-GNXKM59Gx1y3RJNd4‘,
            ‘template_id‘=>‘f1ZvxWXPmwE-FdRmdEwG7H_S3bfa98rhVw5ERQHPSMc‘,
            ‘data‘=>[
                ‘first‘=>[‘value‘=>‘您好,你已成功进行账户充值。‘,‘color‘=>‘#FF0000‘],
                ‘accountType‘=>[‘value‘=>‘充值账户‘,‘color‘=>‘#173177‘],
                ‘account‘=>[‘value‘=>‘张伟‘,‘color‘=>‘#173177‘],
                ‘amount‘=>[‘value‘=>‘100元‘,‘color‘=>‘#173177‘],
                ‘result‘=>[‘value‘=>‘充值成功‘,‘color‘=>‘#173177‘],
                ‘remark‘=>[‘value‘=>‘如有任何疑问请登录会员系统联系在线客服‘,‘color‘=>‘#173177‘]
            ]
        ];

        $data = json_encode($message);
        $res = self::actionCurlRequest($url,$data);

        return json_decode($res,true);

    }

    public function actionGetToken(){
        $url = ‘https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx69c7f72146629b05&secret=7367d829b543a55dc99ddf01c9ca0023‘;
        $res = json_decode(self::actionCurlRequest($url));
        Yii::$app->session[‘wx_token‘] = $res->access_token;
        return $res->access_token;
    }

    public function actionSetMenu(){
        if(!empty(Yii::$app->session[‘wx_token‘])){
            $token = Yii::$app->session[‘wx_token‘];
        }else{
            unset(Yii::$app->session[‘wx_token‘]);
            $token = self::actionGetToken();
        }
        $url = ‘https://api.weixin.qq.com/cgi-bin/menu/create?access_token=‘.$token;
        $data = array(
            ‘button‘=>array(
                array(
                    ‘type‘=>‘view‘,
                    ‘name‘=>‘广告投放‘,
                    ‘url‘=>‘https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx69c7f72146629b05&redirect_uri=http://fx.peita.net/adShared/index.html&response_type=code&scope=snsapi_base&state=123&connect_redirect=1#wechat_redirect‘
                ),
                array(
                    ‘name‘=>‘我的‘,
                    ‘sub_button‘=>array(
                        array(
                            ‘type‘=>‘view‘,
                            ‘name‘=>‘充值‘,
                            ‘url‘=>‘http://www.peita.net‘
                        ),
                        array(
                            ‘type‘=>‘click‘,
                            ‘name‘=>‘查看余额‘,
                            ‘key‘=>‘balance‘
                        )
                    )
                ),
            ),
        );

        //创建菜单
        $res= self::actionCurlRequest($url,json_encode($data,JSON_UNESCAPED_UNICODE));
        return $res;
    }

    public function actionDelMenu(){
        if(!empty(Yii::$app->session[‘wx_token‘])){
            $token = Yii::$app->session[‘wx_token‘];
        }else{
            unset(Yii::$app->session[‘wx_token‘]);
            $token = self::actionGetToken();
        }
        $url = ‘https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=‘.$token;
        $res= self::actionCurlRequest($url);
        return $res;

    }

    public function actionCurlRequest($url,$data=null){
        $curl = curl_init();
        curl_setopt($curl,CURLOPT_URL,$url);
        curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,FALSE);
        curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,FALSE);
        if(!empty($data)){
            curl_setopt($curl,CURLOPT_POST,1);
            curl_setopt($curl,CURLOPT_POSTFIELDS,$data);
        }

        curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }

    public function actionCodeGetUserInfo(){
        $code = Yii::$app->request->get(‘code‘);
        $url = ‘https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx69c7f72146629b05&secret=7367d829b543a55dc99ddf01c9ca0023&code=‘.$code.‘&grant_type=authorization_code‘;
        $res = json_decode(self::actionCurlRequest($url));
        $openid = $res->openid;
        $data = WxUser::find()->where([‘openid‘=>$openid])->one();
        if(empty($data)) return Helper::format_data(SUCC,null);
        return Helper::format_data(SUCC,$data);

    }

    /*
     * ipad 返回
     * @param browser总浏览量,type 根据1,2,3判断返回的广告来源,1付费用户,2商家用户,3后台用户,equipment_imei设备imei,active_id 该设备投放的广告主键id,shop_id 设备所属商家id
     */
     public function actionReturnPlay(){
        $request = Yii::$app->request->post();
        $money = $request[‘browser‘]*0.01;
        if($request[‘type‘] == 1){
            $model = new WxUser();
            $user = new User();
            $models = new Active();
            $order = new Order();
            $Person = new PersonLooking();
            $time = date(‘Ymd‘,time());
            $equipment = equipment::find()->select(‘equipment_id,equipment_imei‘)->where([‘equipment_imei‘=>$request[‘equipment_imei‘]])->andwhere([‘fault_status‘=>0])->one();
            if(empty($equipment)) {
                return Helper::format_data(IMEI,null);
            }
            $PersonLooking = $Person->find()->where([‘equipment_id‘=>$equipment->equipment_id])->andWhere([‘create_time‘=>$time])->one();
            if(empty($PersonLooking)){
                $Person->equipment_id = $equipment->equipment_id;
                $Person->hour_looking = $request[‘browser‘];
                $Person->create_time = $time;
                $Person->save(false);
            }else{
                $PersonLooking->hour_looking += $request[‘browser‘];
                $PersonLooking->save(false);
            }
            if($request[‘status‘] == 1){
                $active = $models->find()->where([‘a_id‘=>$request[‘active_id‘]])->where([‘shop_type‘=>1])->one();
            }elseif($request[‘status‘] == 2){
                $active = $models->find()->where([‘a_id‘=>$request[‘active_id‘]])->where([‘shop_type‘=>2])->one();
            }
            $wx_id = $active->user_id;
            $active->browser += $request[‘browser‘];
            $str = $user->find()->where([‘id‘=>$request[‘shop_id‘]])->one();
            if(empty($str)){
                return Helper::format_data(INVALID_ACCESS_TOKEN,null);
            }
            $money_all = $money*0.3;
            $str->current_money += $money_all;
            $str->money_count += $money_all;
            if($active->save(false) == false){
                return Helper::format_data(ERROR_ACTIVE,$active->getErrors());
            }
            $arr = $order->find()->where([‘order_id‘=>$request[‘order_id‘]])->one();
            if(empty($arr)){
                    return Helper::format_data(INVALID_ACCESS_TOKEN,null);
            }
            $arr->price += $money;
            if($arr->save(false) == false){
                return Helper::format_data(ERROR_ORDER,$arr>getErrors());
            }
            if($request[‘status‘] == 1){  //微信推送
                $data = $model->find()->where([‘id‘=>$wx_id])->one();
                if(empty($data)){
                    return Helper::format_data(INVALID_ACCESS_TOKEN,null);
                }
                if($data->amount < $money){
                    $result = FreeDelivery::deleteAll([‘shop_id‘=>$request[‘shop_id‘]]);
                    $data->amount -= $money;
                    if($data->save(false)){
                        $data->all_money += $data->amount;
                        $data->amount = 0;
                        if($data->save(false)){
                                if($str->save(false)){
                                    $res = self::actionPushMessage($data->openid,$data->all_money,$data->username);
                                    return Helper::format_data(SUCC,[‘shop_id‘=>$request[‘shop_id‘],‘type‘=>1,‘res‘=>json_decode($res)]);
                                }
                            }
                        }
                }
                $data->amount -= $money;
                $data->save(false);
                if($data->save(false) == false)        return Helper::format_data(ERROR_WXUSER,$data->getErrors());
                if($str->save(false)){
                    return Helper::format_data(SUCC,$str->id);
                }
            }elseif($request[‘status‘] == 2){ //个推
                $data = $user->find()->where([‘id‘=>$wx_id])->one();
                if(empty($data)){
                    return Helper::format_data(INVALID_ACCESS_TOKEN,null);
                }
                if($data->amount < $money){
                $result = FreeDelivery::deleteAll([‘shop_id‘=>$request[‘shop_id‘]]);
                if($data->save(false)){
                    $data->money_count += $data->amount;
                    $data->amount = 0;
                    if($data->save(false)){
                            if($str->save(false)){

                                return Helper::format_data(SUCC,[‘shop_id‘=>$request[‘shop_id‘],‘type‘=>1]);
                            }
                        }
                    }
                }
                $data->amount -= $money;
                $data->save(false);
                if($data->save(false) == false)        return Helper::format_data(ERROR_WXUSER,$data->getErrors());
                if($str->save(false)){
                    return Helper::format_data(SUCC,$str->id);
                }
            }

        }elseif($request[‘type‘] == 2){
            $models = new ShopActive();
            $active = $models->find()->where([‘a_id‘=>$request[‘active_id‘]])->one();
            $active->browser += $request[‘browser‘];
            if($active->save(false)){
                return Helper::format_data(SUCC,$active->a_id);
            }
            return Helper::format_data(ERROR_ORDER,$active->getErrors());
        }
        $AdminDelivery = new AdminDelivery();
        $data = $AdminDelivery->find()->where([‘active_id‘=>$request[‘active_id‘]])->one();
        if(empty($data)){
            $AdminDelivery->shop_id = $request[‘shop_id‘];
            $AdminDelivery->active_id = $request[‘active_id‘];
            $AdminDelivery->price = $money;
            $AdminDelivery->delivery_time = date(‘Ymd‘);
            $AdminDelivery->browse_num = $request[‘browser‘];
            if($AdminDelivery->save()){
                return Helper::format_data(SUCC,$AdminDelivery->id);
            }
            return Helper::format_data(ERROR_ORDER,$AdminDelivery->getErrors());
        }
        $data->price += $money;
        $data->browse_num += $request[‘browser‘];
        if($data->save(false)){
            return Helper::format_data(SUCC,$data->id);
        }
        return Helper::format_data(ERROR_ORDER,$data->getErrors());
     }
}
时间: 2024-10-26 06:16:10

微信公众号开发代码参考的相关文章

C#微信公众号开发 -- (五)自定义菜单创建

公众号中,底部都是有自己定义的功能按钮,通过点击某个按钮来实现指定的业务逻辑操作. 下面就来说说这些按钮是怎样放到微信公众平台的,还是先来看看微信的官方解释: 请注意: 1.自定义菜单最多包括3个一级菜单,每个一级菜单最多包含5个二级菜单. 2.一级菜单最多4个汉字,二级菜单最多7个汉字,多出来的部分将会以“...”代替. 3.创建自定义菜单后,菜单的刷新策略是,在用户进入公众号会话页或公众号profile页时,如果发现上一次拉取菜单的请求在5分钟以前,就会拉取一下菜单, 如果菜单有更新,就会刷

利用OpenShift托管Node.js Web服务进行微信公众号开发

最近写了一个微信的翻译机器人.用户只要关注该微信号,发送英文的消息,就能收到中文翻译的回复.后台是用Node.js写的,托管在OpenShift的Paas平台上.翻译过程实际上是调用微软的Bing translation API做的,代码中用到了alexu84的bing-translate和JacksonTian的wechat这两个npm模块.下面把做的过程详细说一下. 1. 微信公众号开发 首先是要到https://mp.weixin.qq.com 申请一个公众号,并申请成为开发者.目前个人只

nodejs + BAE 搭建微信公众号开发平台

闲来无事创建了一个微信公众账号,名曰“深圳生活小助手”, 关注的人不多,平时发一些深圳新闻,趣事啥的,为了丰富公众号的内容,准备添加一些便民查询功能,例如天气预报.快递查询等等. 于是就有了本文的内容. 深圳的读者扫描关注支持下啊... 闲话不多说,本文主要介绍的就是如何基于nodejs和百度云搭建微信公众号开发平台,下一节介绍如何基于该平台实现了一个简单的天气预报查询功能的小例子. 1. 使用Express搭建本地站点 Express 是一个简洁.灵活的 node.js Web 应用开发框架,

C#微信公众号开发系列教程三(消息体签名及加解密)

  C#微信公众号开发系列教程一(调试环境部署) C#微信公众号开发系列教程一(调试环境部署续:vs远程调试) C#微信公众号开发系列教程二(新手接入指南)    距离上一篇博文已经半个月了,本来打算每两天更新一次的,但可怜苦逼码农无日无夜的加班.第一篇博文发表后,博文视点的编辑就找到我,问我想不想出版这个系列,我当时瞬间就想到了王大锤的独白,想想真的是有点小激动,后面按照那边的要求,提交了申请书,也提交了目录,可惜文笔不行,再加上最近太忙,样稿一直没有给他,感觉挺愧疚了.真心希望能帮一下迷茫的

nodejs 中koa框架下的微信公众号开发初始篇

最近在搞微信公众号开发,后端采用的是nodejs下的koa框架,初识后端的菜鸟,自己搞难度太大了,网上找了很多文章,采用的中间件大都是express框架下的,不过好在爬了许多坑之后总算看见点曙光了,遂把探索出来的一点东西拿出来分享,毕竟能力有限,拿出来也是希望大神看到了给点建议, 主要用 koa-wechat 处理验证和消息解析 ,用wechat-api来进行按钮组等api操作,刚开始没什么内容,大家随意看看就好, 废话不多说,直接上代码(这是一个route的代码): var koa = req

微信公众号开发之自动消息回复和自定义菜单

(一)微信公众号开发之VS远程调试 (二)微信公众号开发之基础梳理 (三)微信公众号开发之自动消息回复和自定义菜单 前言 上一篇我们大致讲解了下微信公众号开发的基本原理和流程概述.本章主要是对文本消息回复和自定义菜单做一个记录和分解 消息回复 处理请求,并响应 1)关注 也可参考官网文档:https://mp.weixin.qq.com/wiki 当微信用户关注公众账号时,可以给其适当的提示.可以是欢迎词,可以是帮助提示.示例代码如下: class EventHandler : IHandler

.NET微信公众号开发-5.0微信支付

一.前言 在开始做这个功能之前,我们要做的第一件事情就是思考,如何做这个微信支付,从哪里开始,从哪里入手,官方的sdk说明什么的,有没有什么官方的demo,还有就是老板给我的一些资料齐全不,那些要申请的接口什么的都有没有. 经过自己的一些探索,在老板的催促下终于硬着头皮做完了这个,很坑很坑的微信支付,在此做一些总结,希望对你们有所帮助,本人能力有限,如果有什么说的不好,希望大家多多包涵. 二.开发前准备. 1.0微信支付官方开发者文档 2.0官方demo下载 我们用c#所以选择.net版本 不过

微信公众号开发之准备工作

这是微信公众号开发的第一步.是网页授权的那章的前提. 工作室有关一个订餐系统的开发,我对公众号开发比较感兴趣,所以参与这方面的学习. 本章主要讲述两个方面的内容,一是工具的准备,二是环境的配置. ---------------------------------第一部分:工具的准备 1.做微信公众号开发我们需要一个公众号: 公众号可以官方注册申请,如有不懂,参考搜狗指南.(如需使用高级接口需要认证.) 当然使用,官方给开发者提供的测试号,需要微信号登录注册. 2.然后是需要一个云主机: 我使用的

带领技术小白入门——基于java的微信公众号开发(包括服务器配置、java web项目搭建、tomcat手动发布web项目、微信开发所需的url和token验证)

微信公众号对于每个人来说都不陌生,但是许多人都不清楚是怎么开发的.身为技术小白的我,在闲暇之余研究了一下基于java的微信公众号开发.下面就是我的实现步骤,写的略显粗糙,希望大家多多提议! 一.申请服务器 1.我购买的是阿里云服务器,购买后要设置一下服务器密码,默认用户名是administrator,购买好后如下: 2.申请好后,copy一下此服务器的IP地址(公有),在本地ping一下看看是否可用,j键盘Win+R,输入cmd,输入ping+IP回车,如下即为成功: 二.配置服务器 1.下载远