微信单图文、多图文推送、列表中排序

黄舟
发布: 2016-12-30 10:35:36
原创
2465人浏览过

<?php

/**

* @author yinhuiying(改于)

* @since version - 2014-10-31

* @deprecated version - 2014-10-31

* 腾讯客服接口

*/

class ServiceModel extends Model{



/**

* 客服接口(高级接口)

* @param int $uid

* @param String openid 微信唯一标识

* @param String array 回复数组内容

* @param int type 类型 1表示文字回复 2表示图文回复

* */

public function Service($openid,$array,$type){

switch($type){

case 1: $json = '{

"touser":"'.strval($openid).'",

"msgtype":"text",

"text":

{

"content":"'.$array['content'].'"

}

}';

$this->postService($json);

break;

case 2: $json = '{

"touser":"OPENID",

"msgtype":"image",

"image":

{

"media_id":"MEDIA_ID"

}

}';

$this->postService($json);

break;

case 3: $json = '{

"touser":"OPENID",

"msgtype":"voice",

"voice":

{

"media_id":"MEDIA_ID"

}

}';

$this->postService($json);

break;

case 4: $json = '{

"touser":"OPENID",

"msgtype":"video",

"video":

{

"media_id":"MEDIA_ID",

"title":"TITLE",

"description":"DESCRIPTION"

}

}';

$this->postService($json);

break;

case 5: $json = '{

"touser":"OPENID",

"msgtype":"music",

"music":

{

"title":"MUSIC_TITLE",

"description":"MUSIC_DESCRIPTION",

"musicurl":"MUSIC_URL",

"hqmusicurl":"HQ_MUSIC_URL",

"thumb_media_id":"THUMB_MEDIA_ID"

}

}';

$this->postService($json);

break;

case 6: $json = '{

"touser":"OPENID",

"msgtype":"news",

"news":{

"articles": [

{

"title":"'.$array['title1'].'",

"description":"'.$array['description1'].'",

"url":"'.$array['url1'].'",

"picurl":"'.$array['picurl1'].'"

},

{

"title":"'.$array['title2'].'",

"description":"'.$array['description2'].'",

"url":"'.$array['url2'].'",

"picurl":"'.$array['picurl2'].'"

},

{

"title":"'.$array['title3'].'",

"description":"'.$array['description3'].'",

"url":"'.$array['url3'].'",

"picurl":"'.$array['picurl3'].'"

}

]

}

}';

$this->postService($json);

break;

}

}



public function postService($json){

$access_token = model('WeixinInterface')->getACCESS_TOKEN(330);

//Log :: write("客服接口获得的accessToken是".$access_token, log :: INFO);

$url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$access_token;

model('WeixinInterface')->getHttpResponsePOST($url,$json);



}



}

?>

---------------或者---------------------

MODEL中

public function Service($uid,$json){

self::$wxInterFace = M('WXInterFace','wxmenu');

$access_token = $this->getACCESS_TOKEN($uid);

$url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$access_token;

$this->getHttpResponsePOST($url,$json);

}

在ACTION中 

//图文回复

public function msgReturn(){

$json = '{

"touser":"'.strval($_SESSION['oauthopenid']).'",

"msgtype":"news",

"news":{

"articles": [

{

"title":"大华双十一购房狂欢节,团购优惠等你来!",

"description":"",

"url":"http://dc.exweixin.com/index.php?app=Dhcheap&mod=Index&act=index&aid=11",

"picurl":"http://dc.exweixin.com/data/upload/2014/1031/10/top_img_1.png"

},

{

"title":"一口价房源再享折上折",

"description":"",

"url":"http://dc.exweixin.com/index.php?app=RedPacket&mod=Coupon&act=welcome&uid=330",

"picurl":"http://dc.exweixin.com/data/upload/2014/1031/10/fixed_1.jpg"

},

{

"title":"我要抢红包",

"description":"",

"url":"http://dc.exweixin.com/index.php?app=redPacket&mod=Welcome&act=welcome&uid=330",

"picurl":"http://dc.exweixin.com/data/upload/2014/1031/10/rob_1.jpg"

},

{

"title":"土豪排行榜",

"description":"",

"url":"http://dc.exweixin.com/index.php?app=RedPacket&mod=Index&act=ranking",

"picurl":"http://dc.exweixin.com/data/upload/2014/1031/10/ranking_1.jpg"

},

{

"title":"我的钱包",

"description":"",

"url":"http://dc.exweixin.com/index.php?app=RedPacket&mod=Index&act=person&openid='.strval($_SESSION['oauthopenid']).'",

"picurl":"http://dc.exweixin.com/data/upload/2014/1031/10/packet_1.jpg"

}

]

}

}';



//调用客服接口

$uid=330;

M('CustomService','wxmenu')->Service($uid,$json);

}

//----------------------------------//

列表中排序、效果

1、

2、

3、

代码

<li class="count">{$i+$n}</li>
登录后复制

 以上就是微信单图文、多图文推送、列表中排序的内容,更多相关内容请关注php中文网(www.php.cn)!

微信app下载
微信app下载

微信是一款手机通信软件,支持通过手机网络发送语音短信、视频、图片和文字。微信可以单聊及群聊,还能根据地理位置找到附近的人,带给大家全新的移动沟通体验,有需要的小伙伴快来保存下载体验吧!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号