Example #1
0
function get_qrafe($db, $ecs, $u_id = '')
{
    //$wx_config,$post['u_id'],$post['r_host']
    $data['wx_config'] = $db->getRow("SELECT * FROM `wxch_config` WHERE `id` = 1");
    foreach ($data as $k => $v) {
        if (is_array($v)) {
            $data[$k] = json_encode($v);
        }
    }
    $data['u_id'] = $u_id;
    $base_url = $db->getOne("SELECT `cfg_value` FROM `wxch_cfg` WHERE `cfg_name` = 'baseurl'");
    $arr = explode("/", $base_url);
    $data['r_host'] = $arr[2];
    $wx_data['wx_user'] = get_wxuser($db, $u_id, $ecs);
    $wx_data['wx_user']['headimgurl'] = get_wxheadimgurl($wx_data['wx_user']['headimgurl'], 132);
    $data['headimgurl'] = $wx_data['wx_user']['headimgurl'];
    $url = 'http://api.weixincaihong.com/index.php/wch/qr/qr_scene';
    if ($_GET['debug'] == 1) {
        $url = 'http://api.weixincaihong.com/index.php/wch/qr/qr_scene/post';
    }
    $res = curl_grab_page($url, $data);
    if ($_GET['debug'] == 2) {
        print_r($res);
        exit;
    }
    $json = json_decode($res);
    $wx_data['qr_img'] = $json->qr_img;
    return $wx_data;
}
} elseif ($orders['pay_status'] == 2) {
    $pay_status = '支付状态:已付款';
}
$http_ret1 = stristr($cfg_order['image'], 'http://');
$http_ret2 = stristr($cfg_order['image'], 'http:\\');
if ($http_ret1 or $http_ret2) {
    $w_picurl = $cfg_order['image'];
} else {
    $w_picurl = $cfg_baseurl . $cfg_order['image'];
}
$post_msg = '{
   "touser":"******",
   "msgtype":"news",
   "news":{
       "articles": [
        {
            "title":"' . $w_title . '",
            "description":"' . $w_description . '",
            "url":"' . $w_url . '",
            "picurl":"' . $w_picurl . '"
        }
        ]
   }
}';
$ret_json = curl_grab_page($url, $post_msg);
$ret = json_decode($ret_json);
if ($ret->errmsg != 'ok') {
    $access_token = new_access_token($db);
    $url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' . $access_token;
    curl_grab_page($url, $post_msg);
}
Example #3
0
            {
                "title":"' . $w_title . '",
                "description":"' . $w_description . '",
                "url":"' . $w_url . '",
                "picurl":"' . $picurl . '"
            }
            ]
       }
   }';
    $ret_json = curl_grab_page($url, $post_msg);
    $ret = json_decode($ret_json);
    //var_dump($ret);exit();
    if ($ret->errmsg != 'ok') {
        $access_token = new_access_token($db);
        $url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' . $access_token;
        $ret_json = curl_grab_page($url, $post_msg);
        $ret = json_decode($ret_json);
    }
}
function new_access_token($db)
{
    $time = time();
    $ret = $db->getRow("SELECT * FROM `hhs_weixin_config` WHERE `id` = 1");
    $appid = $ret['appid'];
    $appsecret = $ret['appsecret'];
    $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$appsecret}";
    $ret_json = curl_get_contents($url);
    $ret = json_decode($ret_json);
    setcookie("access_token", $ret->access_token, time() + 7000, '/');
    return $ret->access_token;
}
Example #4
0
        $access_token = access_token($db);
        $url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' . $access_token;
        $post_msg = '{
           "touser":"******",
           "msgtype":"text",
           "text":
           {
                "content":"' . $content . '"
           }
       }';
        $ret_json = curl_grab_page($url, $post_msg);
        $ret = json_decode($ret_json);
        if ($ret->errcode == '40001') {
            $access_token = new_access_token($db);
            $url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' . $access_token;
            $ret_json = curl_grab_page($url, $menu);
            $ret = json_decode($ret_json);
        } elseif ($ret->errcode == '45015') {
            $link[0] = array('href' => 'wxch_users.php?act=list', 'text' => '用户列表');
            sys_msg('回复时间超过限制', 0, $link);
        } elseif ($ret->errcode == '48001') {
            $link[0] = array('href' => 'wxch_users.php?act=list', 'text' => '用户列表');
            sys_msg('公众号不具备该功能', 5, $link);
        } elseif ($ret->errcode == '0') {
            $db->query("INSERT INTO `wxch_message` (`wxid`, `message`, `dateline`) VALUES\n( '{$wxid}', '{$content}', {$time});");
            $href = 'wxch_users.php?act=send&uid=' . $uid;
            $link[0] = array('href' => $href, 'text' => '消息回复');
            sys_msg('回复成功', 0, $link);
        }
    }
}
 if ($_POST) {
     $action_name = $_POST['action_name'];
     $scene = $_POST['scene'];
     $function = $_POST['function'];
     $type = 'qr';
     $expire_seconds = $_POST['expire_seconds'];
     $ret = $db->getRow("SELECT * FROM `wxch_qr` WHERE `action_name` = 'QR_LIMIT_SCENE' ORDER BY `scene_id` DESC");
     $scene_id = $ret['scene_id'] + 1;
     $json_arr = array('action_name' => $action_name, 'action_info' => array('scene' => array('scene_id' => $scene_id)));
     $data = json_encode($json_arr);
     access_token($db);
     $ret = $db->getRow("SELECT `access_token` FROM `wxch_config`");
     $access_token = $ret['access_token'];
     if (strlen($access_token) >= 64) {
         $url = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=' . $access_token;
         $res_json = curl_grab_page($url, $data);
         $json = json_decode($res_json);
     }
     $ticket = $json->ticket;
     if ($ticket) {
         $ticket_url = urlencode($ticket);
         $ticket_url = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=' . $ticket_url;
         $qrimg = curl_get_contents($ticket_url);
         $time = time();
         $path = '../images/upload/' . $time . '.jpg';
         @file_put_contents($path, $qrimg);
         $qr_path = '/images/upload/' . $time . '.jpg';
         if (@filesize(ROOT_PATH . $qr_path) < 10240) {
             $qr_path = '';
         }
         $insert_sql = "INSERT INTO `wxch_qr` (`type`,`expire_seconds`,`action_name`,`ticket`, `scene_id`, `scene` ,`qr_path`,`function`) VALUES\r\n   ('{$type}','{$expire_seconds}','{$action_name}', '{$ticket}',{$scene_id}, '{$scene}' ,'{$qr_path}','{$function}')";
function create_menu($db)
{
    access_token($db);
    $ret = $db->getRow("SELECT `access_token` FROM `wxch_config`");
    $access_token = $ret['access_token'];
    if (strlen($access_token) >= 64) {
        $url = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token=' . $access_token;
        $data = array();
        $sql = "SELECT * FROM  `wxch_menu` WHERE  `aid` =0";
        $data['first'] = $db->getAll($sql);
        foreach ($data['first'] as $k => $v) {
            if (empty($data['first'][$k]['name'])) {
                unset($data['first'][$k]);
            } else {
                $data['first'][$k]['name'] = urlencode($v['name']);
                if ($v['menu_type'] == 'click') {
                    $data['first'][$k]['array'] = array('type' => $v['menu_type'], 'name' => $data['first'][$k]['name'], 'key' => $v['value']);
                } elseif ($v['menu_type'] == 'view') {
                    $data['first'][$k]['array'] = array('type' => $v['menu_type'], 'name' => $data['first'][$k]['name'], 'url' => $v['value']);
                }
            }
        }
        $sql = "SELECT * FROM  `wxch_menu` WHERE  `aid` =1";
        $data['second1'] = $db->getAll($sql);
        $second1 = 'no';
        foreach ($data['second1'] as $k => $v) {
            if (empty($data['second1'][$k]['name'])) {
                unset($data['second1'][$k]);
            } else {
                $v['value'] = urlencode($v['value']);
                $v['name'] = urlencode($v['name']);
                if ($v['menu_type'] == 'click') {
                    $array1[] = array('type' => $v['menu_type'], 'name' => $v['name'], 'key' => $v['value']);
                } elseif ($v['menu_type'] == 'view') {
                    $array1[] = array('type' => $v['menu_type'], 'name' => $v['name'], 'url' => $v['value']);
                }
                $second1 = 'yes';
            }
        }
        $sql = "SELECT * FROM  `wxch_menu` WHERE  `aid` =2";
        $data['second2'] = $db->getAll($sql);
        $second2 = 'no';
        foreach ($data['second2'] as $k => $v) {
            if (empty($data['second2'][$k]['name'])) {
                unset($data['second2'][$k]);
            } else {
                $v['value'] = urlencode($v['value']);
                $v['name'] = urlencode($v['name']);
                if ($v['menu_type'] == 'click') {
                    $array2[] = array('type' => $v['menu_type'], 'name' => $v['name'], 'key' => $v['value']);
                } elseif ($v['menu_type'] == 'view') {
                    $array2[] = array('type' => $v['menu_type'], 'name' => $v['name'], 'url' => $v['value']);
                }
                $second2 = 'yes';
            }
        }
        $sql = "SELECT * FROM  `wxch_menu` WHERE  `aid` =3";
        $data['second3'] = $db->getAll($sql);
        $second3 = 'no';
        foreach ($data['second3'] as $k => $v) {
            if (empty($data['second3'][$k]['name'])) {
                unset($data['second3'][$k]);
            } else {
                $v['value'] = urlencode($v['value']);
                $v['name'] = urlencode($v['name']);
                if ($v['menu_type'] == 'click') {
                    $array3[] = array('type' => $v['menu_type'], 'name' => $v['name'], 'key' => $v['value']);
                } elseif ($v['menu_type'] == 'view') {
                    $array3[] = array('type' => $v['menu_type'], 'name' => $v['name'], 'url' => $v['value']);
                }
                $second3 = 'yes';
            }
        }
        if ($second1 == 'yes') {
            $sarr1 = array('name' => $data['first'][0]['name'], 'sub_button' => $array1);
        } elseif ($second1 == 'no') {
            $sarr1 = $data['first'][0]['array'];
        }
        if ($second2 == 'yes') {
            $sarr2 = array('name' => $data['first'][1]['name'], 'sub_button' => $array2);
        } elseif ($second2 == 'no') {
            $sarr2 = $data['first'][1]['array'];
        }
        if ($second3 == 'yes') {
            $sarr3 = array('name' => $data['first'][2]['name'], 'sub_button' => $array3);
        } elseif ($second3 == 'no') {
            $sarr3 = $data['first'][2]['array'];
        }
        $arr = array('button' => array($sarr1, $sarr2, $sarr3));
        $menu = urldecode(json_encode($arr));
        $ret_json = curl_grab_page($url, $menu);
        $ret = json_decode($ret_json);
        if (!$ret->errcode == '0') {
            $access_token = new_access_token($db);
            $url = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token=' . $access_token;
            $ret_json = curl_grab_page($url, $menu);
            $ret = json_decode($ret_json);
        }
        return $ret;
    } else {
        $access_token = new_access_token($db);
        return FALSE;
    }
}
Example #7
0
<?php

define('IN_ECS', true);
require dirname(__FILE__) . '/../includes/init.php';
access_token($db);
$ret = $db->getRow("SELECT * FROM `wxch_config` WHERE `id` = 1");
$access_token = $ret['access_token'];
$type_media = 'image';
$upload_url = 'http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=' . $access_token . '&type=' . $type_media;
$post_data = array('media' => '@' . dirname(__FILE__) . '/../images/tenpayc2c.jpg');
$ret_json = curl_grab_page($upload_url, $post_data);
$ret = json_decode($ret_json);
$media_id = $ret->media_id;
$get_url = 'http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=' . $access_token . '&media_id=' . $media_id;
$ret_media = curl_get_contents($get_url);
file_put_contents('test.jpg', $ret_media);
echo '<img src="test.jpg"/>';
function access_token($db)
{
    $ret = $db->getRow("SELECT * FROM `wxch_config` WHERE `id` = 1");
    $appid = $ret['appid'];
    //AppId 18
    $appsecret = $ret['appsecret'];
    //AppSecret 32
    $access_token = $ret['access_token'];
    $dateline = $ret['dateline'];
    $time = time();
    //    echo ($time - $dateline);exit;
    if ($time - $dateline >= 7200) {
        $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$appsecret}";
        $ret_json = curl_get_contents($url);
Example #8
0
    $field = $_GET['field'];
    if ($_POST['goto'] == 'update') {
        $contents = $_POST['contents'];
        $res = $db->query("UPDATE `{$table}` SET `{$field}` = '{$contents}' WHERE `id` =1;");
        if ($res) {
            echo 'succeed';
            //succeed
        } else {
            echo 'failed';
        }
    }
}
$passapi = $db->getOne("SELECT `cfg_value` FROM `wxch_cfg` WHERE `cfg_name` = 'baseurl'");
$api = array('passapi' => $passapi);
$url = 'http://api.weixincaihong.com/index.php/wch/api';
curl_grab_page($url, $api);
function curl_get_contents($url)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    //curl_setopt($ch,CURLOPT_HEADER,1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    curl_setopt($ch, CURLOPT_USERAGENT, _USERAGENT_);
    curl_setopt($ch, CURLOPT_REFERER, _REFERER_);
    @curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
    @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    $r = curl_exec($ch);
    curl_close($ch);
Example #9
0
 }
 $ustream = curl_grab_page($url);
 preg_match_all('/cid=(.+?)&amp/', $ustream, $matches, PREG_SET_ORDER);
 $channel_id = trim($matches[1][1]);
 if (strlen($channel_id) == 0) {
     $result = '<font color=red><b>Error: Unable to determine channel ID.</b></font><br/><br/>';
     $error = true;
 } else {
     preg_match_all('/<meta property="og:title" content="(.*)" \\/>/', $ustream, $matches, PREG_SET_ORDER);
     $channel_title = trim($matches[0][1]);
     // 20120727 -- Ustream HTML was updated
     //preg_match_all('/<meta property="og:image" content="(.*)" \/>/', $ustream, $matches, PREG_SET_ORDER);
     //$channel_thumb = trim($matches[0][1]);
     preg_match_all('/<img class="image" alt="(.*)" width="66" height="66" src="(.*)" rel="(.*)" \\/>/', $ustream, $matches, PREG_SET_ORDER);
     $channel_thumb = trim($matches[0][2]);
     $data = curl_grab_page(str_replace('[[[ChannelID]]]', $channel_id, $amf_url));
     preg_match_all('/streamName\\W\\W\\W(.+?)\\x00/', $data, $matches, PREG_SET_ORDER);
     $play_path = trim($matches[0][1]);
     preg_match_all('/cdnUrl\\W\\W\\S(.+?)\\x00/', $data, $matches, PREG_SET_ORDER);
     $tc_url = trim($matches[0][1]);
     preg_match_all('/fmsUrl\\W\\W\\S(.+?)\\x00/', $data, $matches, PREG_SET_ORDER);
     $tc_url2 = trim($matches[0][1]);
     if (strlen($tc_url) == 0) {
         if (strlen($tc_url2) == 0) {
             $result = '<font color=red><b>Error: Not a live feed.</b></font><br/><br/>';
             $error = true;
         } else {
             $new = str_replace('/ustreamVideo', ':1935/ustreamVideo', $tc_url2);
             $rtmp_url = $new . '/';
         }
     } else {