代码拉取完成,页面将自动刷新
同步操作将从 dfbazhu/ecshop_B2C商城多终端自适应响应式布局模板 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
<?php
require(ROOT_PATH . 'mobile/include/lib_weixintong.php');
$time = time();
$access_token = access_token($db);
$url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$access_token;
$sql_two="SELECT wxid FROM " . $GLOBALS['ecs']->table('users') . " WHERE user_id = '$up_uid'";
$wxid=$GLOBALS['db']->GetOne($sql_two);
$w_title="您有新的下线加入,敬请关注!";
$w_description="下线及下线用户的消费您都将有分成。";
$config['site_url']="http://".$_SERVER['HTTP_HOST']."/";
$site_url=$config['site_url'];
$w_url=$site_url."mobile/distribute.php?act=fenxiao1&wxid=".$wxid;
$w_picurl="";
$post_msg = '{
"touser":"'.$wxid.'",
"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;
$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 ". $GLOBALS['ecs']->table('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);
if($ret->access_token)
{
$db->query("UPDATE ". $GLOBALS['ecs']->table('weixin_config') ." SET `access_token` = '$ret->access_token',`dateline` = '$time' WHERE `id` =1;");
}
return $ret->access_token;
}
function access_token($db)
{
$ret = $db->getRow("SELECT * FROM ". $GLOBALS['ecs']->table('weixin_config') ." WHERE `id` = 1");
$appid = $ret['appid'];
$appsecret = $ret['appsecret'];
$access_token = $ret['access_token'];
$dateline = $ret['dateline'];
$time = time();
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);
$ret = json_decode($ret_json);
if($ret->access_token)
{
$db->query("UPDATE ". $GLOBALS['ecs']->table('weixin_config') ." SET `access_token` = '$ret->access_token',`dateline` = '$time' WHERE `id` =1;");
return $ret->access_token;
}
}
elseif(empty($access_token))
{
$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);
if($ret->access_token)
{
$db->query("UPDATE ". $GLOBALS['ecs']->table('weixin_config') ." SET `access_token` = '$ret->access_token',`dateline` = '$time' WHERE `id` =1;");
return $ret->access_token;
}
}
else
{
return $access_token;
}
}
function curl_get_contents($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
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);
return $r;
}
function curl_grab_page($url,$data,$proxy='',$proxystatus='',$ref_url='')
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($proxystatus == 'true')
{
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
}
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
if(!empty($ref_url))
{
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_REFERER, $ref_url);
}
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
ob_start();
return curl_exec ($ch);
ob_end_clean();
curl_close ($ch);
unset($ch);
}
?>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。