예제 #1
0
 public function __construct()
 {
     vendor("wechat");
     $wechat = new wechat();
     $wechat->valid();
     $wechat->createMenu();
 }
예제 #2
0
 function save_weixin_session($code)
 {
     global $log;
     $wechatObj = new wechat();
     $data = $wechatObj->getWebAccessToken($code);
     if (!empty($data['openid'])) {
         file_put_contents($log, '\\nSuccess Get: ' . json_encode($data), FILE_APPEND);
         $wechatObj->addUser($data["access_token"], $data['openid']);
         api_proxy('paper_related_save_user_session', $data['openid']);
     }
 }
예제 #3
0
파일: wechat.php 프로젝트: epodak/linkatzju
<?php 
/******************
 * 和微信通讯
 * ****************/
//自定义和微信验证的token
define("TOKEN", "weixin");
$wechatObj = new wechat();
//$wechatObj->valid();    //这句用来最开始和微信验证,验证成功之后要注释掉这句
$wechatObj->responseMsg();
class wechat
{
    public function valid()
    {
        $echoStr = $_GET["echostr"];
        //valid signature , option
        if ($this->checkSignature()) {
            echo $echoStr;
            exit;
        }
    }
    private function checkSignature()
    {
        // you must define TOKEN by yourself
        if (!defined("TOKEN")) {
            throw new Exception('TOKEN is not defined!');
        }
        $signature = $_GET["signature"];
        $timestamp = $_GET["timestamp"];
        $nonce = $_GET["nonce"];
        $token = TOKEN;
        $tmpArr = array($token, $timestamp, $nonce);
예제 #4
0
<?php

include_once '../includePackage.php';
include_once $GLOBALS['mypath'] . '/wechat/interfaceHandler.php';
include_once $GLOBALS['mypath'] . '/wechat/wechat.php';
include_once $GLOBALS['mypath'] . '/wechat/serveManager.php';
include_once 'reply.php';
//mylog('reach');
$weixin = new wechat(WEIXIN_ID);
$myHandler = new interfaceHandler(WEIXIN_ID);
$weixin->valid();
$msg = $weixin->receiverFilter();
$random = rand(1000, 9999);
//mylog(getArrayInf($msg));
if (in_array($msg['MsgType'], array('text', 'voice', 'img'))) {
    //    mylog('inarray');
    $mode = getWechatMode($msg['from']);
    //    mylog($mode);
    switch ($mode) {
        case 'normal':
            normalReply($weixin, $msg);
            break;
        case 'kf':
            $weixin->toKFMsg();
            sendKFMessage($msg['from'], '您好,有什么可以帮助您?');
            break;
    }
}
if ($msg['MsgType'] == 'event') {
    include_once 'event.php';
    if (in_array($msg['Event'], array('VIEW', 'kf_create_session', 'kf_close_session'))) {
예제 #5
0
         unset($_SESSION['thumb']);
     } else {
         $error = 0;
         // 修改失败
     }
 }
 $file['error'] = $error;
 if ($file['error'] == 1 && $public == 1) {
     //客服接口
     require_once '../../../common/php/configSelf.php';
     $sql_thumb = "select thumb from wx_talent_recruit where id='{$modify_id}'";
     $res_thumb = $db->getrow($sql_thumb);
     $picUrl = "http://" . IP . "/wechat-subscribe-master" . substr($res_thumb['thumb'], 8);
     require_once '../../../common/php/sdk.php';
     $access_token = getAccessToken($appIdSelf, $appSecretSelf);
     $wx = new wechat($appIdSelf, $appSecretSelf, $access_token);
     //获取文章的url
     $url = " http://" . IP . "/wechat-subscribe-master/wechat/talentRecruit/html/jobdetail.html?articleid=" . $modify_id;
     $userInfoList = $wx->getUserInfo();
     foreach ($userInfoList as $key_user => $val_user) {
         $data1[$key_user]['touser'] = $val_user;
         $data1[$key_user]['msgtype'] = "news";
         //	echo $data ['title'];die;
         $data1[$key_user]['news']['articles'][0]['title'] = urlencode($positionName);
         $data1[$key_user]['news']['articles'][0]['description'] = "";
         $data1[$key_user]['news']['articles'][0]['url'] = $url;
         $data1[$key_user]['news']['articles'][0]['picurl'] = $picUrl;
     }
     $wx->sendMsgToAll($data1);
     //end客服接口
 }
예제 #6
0
<?php

header("Content-type:text/html;charset=utf-8");
require_once 'comm.php';
define("TOKEN", "goalfriend");
$wechat = new wechat();
if (isset($_GET['echostr'])) {
    $wechat->valid();
} else {
    $wechat->getMessage();
}
class wechat
{
    public function valid()
    {
        $echoStr = $_GET["echostr"];
        if ($this->checkSignature()) {
            echo $echoStr;
            exit;
        }
    }
    public function getMessage()
    {
        $object = $GLOBALS["HTTP_RAW_POST_DATA"];
        $object = simplexml_load_string($object, 'SimpleXMLElement', LIBXML_NOCDATA);
        $RX_TYPE = trim($object->MsgType);
        //获取消息类型
        switch ($RX_TYPE) {
            case "event":
                $result = $this->receiveEvent($object);
                break;
 $upload['error'] = $flag;
 //将多图文消息用群发接口推送到微信端
 if ($upload['error'] == 1) {
     //过滤掉不推送的文章
     foreach ($articles as $key_arti => $val_arti) {
         if ($val_arti['istoAll'] == 0) {
             array_splice($articles, $key_arti, 1);
         }
     }
     // var_dump($articles);die;
     if (!empty($articles)) {
         require_once '../../../common/php/configSelf.php';
         require_once '../../../common/php/config.php';
         require_once '../../../common/php/sdk.php';
         $access_token = getAccessToken($appIdSelf, $appSecretSelf);
         $wx = new wechat($appIdSelf, $appSecretSelf, $access_token);
         if ($subtype == 'submit') {
             foreach ($articles as $key_art => $val_art) {
                 //将内容中的图片上传到微信服务器,获取到media_id
                 preg_match_all('/<img.*? src=\\"?(.*?\\.(jpg|jpeg|gif|bmp|bnp|png|mp4))\\"?.*?>/i', $val_art['content'], $match);
                 $result_media1 = $match[1];
                 //var_dump( $result_media1);die;
                 foreach ($result_media1 as $key_media => $val_media) {
                     $url_media = explode('/ueditor', $val_media);
                     $url_me = root2 . "/ueditor" . $url_media[1];
                     $urldata = array("media" => "@" . $url_me);
                     $urlmedia = $wx->getMediaUrl($urldata);
                     $val_art['content'] = str_replace($val_media, '\\"' . $urlmedia, $val_art['content']);
                 }
                 //获取缩略图media_id
                 $arr = explode("/", $val_art['thumb']);
예제 #8
0
파일: index.php 프로젝트: btbj/wechat
<?php

$mypath = $_SERVER['DOCUMENT_ROOT'] . '/wechat';
include_once $mypath . '/includes/magicquotes.inc.php';
include_once $mypath . '/includes/db.inc.php';
include_once $mypath . '/includes/helpers.inc.php';
include_once $mypath . '/class/wechat.php';
if (isset($_GET['id'])) {
    wxlog('fetch,to:' . $_GET['id']);
    $weixinId = $_GET['id'];
    $query = pdoQuery('duty_tbl', array('duty'), array('weixin_id' => $weixinId), ' limit 1');
    $data = $query->fetch();
    $decodeData = json_decode($data['duty'], true);
    $weixin = new wechat($weixinId);
    $weixin->valid();
    $msg = $weixin->receiverFilter();
    foreach ($decodeData['dutyContent'] as $row) {
        //            wxlog('include:'.$mypath.'/'.$row);
        $query = pdoQuery('module_config_tbl', array('config'), array('weixin_id' => $weixinId, 'module_path' => $row), ' limit 1');
        if ($config = $query->fetch()) {
            $config = json_decode($config['config'], true);
            $config = $config['config'];
        }
        include_once $mypath . '/' . $row;
    }
    echo '';
    eixt;
}
header('location: admin/index.php');
예제 #9
0
session_start();
include 'config.php';
include 'database.php';
include 'wechat.php';
//$db = new Database($dbconfig);
//
//$sql =  "UPDATE counter SET count_number = count_number + 1";
//$db->query($sql);
//
//$sql =  "SELECT * FROM counter";
//$results = $db->query($sql);
//
//$count = $db->getResults($results);
$now = time();
//$xml = simplexml_load_string($row['xml_in']);
$wechat = new wechat();
$accessToken = $wechat->getAccessToken();
echo $accessToken;
//var_dump($_SESSION);
$touser = '******';
$jsonOutput = json_encode(array('touser' => $touser, 'msgtype' => 'text', 'text' => array('content' => 'It works! PUSH SCRIPT ' . $count['count_number'])));
$test = $wechat->curl_download('https://api.wechat.com/cgi-bin/message/custom/send?access_token=' . $accessToken, $jsonOutput, true);
// end reply
//    $sql = 'INSERT INTO xml_logs (`xml_in`, `xml_out`) VALUES ("code: '.$test->errcode.'  message: '.$test->errmsg.' counter: '.$count['count_number'].'", "<pre>'.var_export($test, true).'</pre>")';
//    $db->query($sql);
//Echo response from API
echo '<pre>';
var_dump($test);
echo '</pre>';
//
////shows rows
예제 #10
0
<?php

class wechat
{
    private $appid = 'wxd8026f76755c7b19';
    private $scope = 'snsapi_userinfo';
    public function authorize()
    {
        $protocol = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? "https://" : "http://";
        $uri = urlencode("{$protocol}{$_SERVER['HTTP_HOST']}/challenge/");
        //    echo $uri;
        $redirect_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . $this->appid . "&redirect_uri=http%3A%2F%2F120.25.234.214%3A8080%2Fchallenge%2Ftest%2Findex.php&response_type=code&scope=" . $this->scope . "&state=STATE#wechat_redirect";
        header("Location: {$redirect_url}");
        exit;
    }
}
$wc = new wechat();
$wc->authorize();