【小程序】小程序页面定位(类似html锚点)

Continue Read..
goTo:function (id) {
        const q =wx.createSelectorQuery();
        q.select("#"+id).boundingClientRect();
        q.selectViewport().scrollOffset();
        q.exec((res)=>{
            if(res[0] && res[1]){
                console.log("跳转",res[0].top+res[1].scrollTop);
                wx.pageScrollTo({
                    scrollTop:res[0].top+res[1].scrollTop -100,
                    duration:300
                })
            }
        })
    },
    setToView:function (room_id, bed_id) {
        var toView = 'room_bed_'+ room_id + '_' + bed_id;
        console.log("toView===", toView);

        this.setData({
            toView: toView
        });
        var self = this;
        setTimeout(function () {
            console.log("self.data.toView===", self.data.toView);
            self.goTo(self.data.toView);
        }, 1000);

    }


声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【微信】微信分享功能(非官方) 破解版

Continue Read..

<input type="hidden" value="http://www.wulinlw.org" id='share_link'>
<input type="hidden" value='1412922457923.jpg' id='share_img'>
<input type="hidden" value='这里是舞林cuzn博客' id='share_title'>
<input type="hidden" value='这里是舞林cuzn博客' id='share_desc'>
<input type="hidden" value="http://www.wulinlw.org" id='share_callback_link'>

<script src="/gonggong/js/jquery.min.js"></script>
<script src="/gonggong/js/wxfenxiang.js"></script>

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【微信】获取微信服务器IP和怎么获取微信access_token的值

Continue Read..
//通过access_token获取微信服务器IP
function getWxIp(){   
    $arr = get_access_token();
    $url = "https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=".$arr['access_token'];
    $res = getWxUrl($url);
    return json_decode($res, true);
}
//获取access_token
function get_access_token(){
    $key = "access_token";
    $data = S($key);
    if(!$data){
   $url_get = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . C("Wx_appid") . '&secret=' . C("Wx_token");
   $data = json_decode(curlGet($url_get), true);
   S($key,$data,7200);
    }
    return $data;
}
function curlGet($url){
    $ch = curl_init();
    $header = "Accept-Charset: utf-8";
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $temp = curl_exec($ch);
    return $temp;
}

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【微信】禁止微信浏览器后退

Continue Read..
公司做了投票的页面  然后被刷票了  找了一天的BUG  终于被JS兄无意间发现了()   真心大BUG
正常程序是点击后刷新页面 换人投票的 
结果微信可以后退  然后继续出来这个人   就可以无限投票了  
下面就是防止微信浏览器后退的
<script>
document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
    WeixinJSBridge.call('hideToolbar');
    WeixinJSBridge.call('hideOptionMenu');
});
</script>
<SCRIPT language="JavaScript">
javascript:window.history.forward(1);
</SCRIPT>


php端
header("Cache-control:no-cache,no-store,must-revalidate");
header("Pragma:no-cache");
header("Expires:0");

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【微信】弹出验证,获取微信用户信息

Continue Read..
function getWxUrl($url, $param = null) {
    if($param != null) {
        $query = http_build_query($param);
        $url = $url . '?' . $query;
    }   
    $ch = curl_init();
    if(stripos($url, "https://") !== false){
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    }   
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
    $content = curl_exec($ch);
    $status = curl_getinfo($ch);
    curl_close($ch);
    if(intval($status["http_code"]) == 200) {
       return $content;
    }else{
        echo $status["http_code"];
        return false;
    }   
}



function getWxAll(){
    if(!strpos($_SERVER['HTTP_USER_AGENT'],"MicroMessenger")){echo '请在微信中打开1'; exit();}
    $AppID = C("Wx_appid"); $AppSecret = C("Wx_token");
    $url = urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
    $openid_cookiename = substr(md5($_SERVER['HTTP_USER_AGENT'].get_client_ip()),8,8);
    $openid = cookie($openid_cookiename);
    //$openid = "";     //这里是测试的时候用的 测试的时候打开
    if(empty($openid)){
        $codeid = $_GET['code'];
        if(empty($codeid)){
        //echo "a";
            Redirect('https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$AppID.'&redirect_uri='.$url.'&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect');
            exit();
        }else{
        //echo "b";
            $response = getWxCode($codeid);
            if($response == false) {
                return false;
            }
            $user = $response;
           // dump($user);die;
            if (isset($user->error) || $user->openid == "") {
              echo '请在微信中打开2'; exit();
            }
            $openid = $user->openid;
            if(empty($openid)){echo '请在微信中打开3';exit();}
            cookie($openid_cookiename,$openid,30*24*60*60);
        }
    }
}

    //通过第三方获取CODE用户基本信息(未关注也可以获取)
function getWxCode($code){   
$AppID = C("Wx_appid"); $AppSecret = C("Wx_token");
    $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$AppID."&secret=".$AppSecret."&code=".$code."&grant_type=authorization_code";
    $res = getWxUrl($url);
    $data = json_decode($res, true);
    $scope = $data['scope'];
    //当为弹出授权时
    if ($scope == 'snsapi_userinfo'){
   $access_token = $data['access_token'];
   $openid = $data['openid'];
   $url = "https://api.weixin.qq.com/sns/userinfo?access_token=".$access_token."&openid=".$openid;
        $res = getWxUrl($url);
    }
    return json_decode($res, true);
}

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【微信】限制只允许在微信中打开, 并且能够隐藏获取OPENID。

Continue Read..
  if(!strpos($_SERVER['HTTP_USER_AGENT'],"MicroMessenger")){echo '请在微信中打开'; exit();}
$AppID = 'wx9872b52811ccdbb1'; $AppSecret = '5e5c983fabadc130e2ea5120f7d09a90';
$url = urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$openid_cookiename = substr(md5($_SERVER['HTTP_USER_AGENT'].getClientIp()),8,8);
$openid = cookie($openid_cookiename);
if(empty($openid)){
$codeid = $_GET['code'];
if(empty($codeid)){
Redirect('https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$AppID.'&redirect_uri='.$url.'&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect');
exit();
}else{
$response = $this->get('https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$AppID.'&secret='.$AppSecret.'&code='.$codeid.'&grant_type=authorization_code');
if($response == false) {
return false;
}
$user = json_decode($response);
if (isset($user->error) || $user->openid == "") {
echo '请在微信中打开'; exit();
}
$openid = $user->openid;
if(empty($openid)){echo '请在微信中打开';exit();}
cookie($openid_cookiename,$openid,30*24*60*60);
}
}



public function get($url, $param = null) {
if($param != null) {
$query = http_build_query($param);
$url = $url . '?' . $query;
}   
$ch = curl_init();
if(stripos($url, "https://") !== false){
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}   
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
$content = curl_exec($ch);
$status = curl_getinfo($ch);
curl_close($ch);
if(intval($status["http_code"]) == 200) {
return $content;
}else{
echo $status["http_code"];
return false;
}   
}
限制只允许在微信中打开, 并且能够隐藏获取OPENID。

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【微信】根据公共号的token获取access_token

Continue Read..

function curlGet_cuzn($url){
        $ch = curl_init();
        $header = "Accept-Charset: utf-8";
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $temp = curl_exec($ch);
        return $temp;
}
function getAccessToken_cuzn(){
    $map ['token'] = get_token ();
    $info = M ( 'member_public' )->where ( $map )->find ();
    $key = "access_token".$map ['token'];
    $data = S($key);
    if(!$data  || time()- $data['create_time'] > 7200 ){
        $url_get = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $info ['appid'] . '&secret=' . $info ['secret'];
        $data = json_decode(curlGet_cuzn($url_get), true);
        $data['token'] = $map ['token'];
        $data['create_time'] = time();
        S($key,$data,7200);
    }
    return $data;
}

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【微信】通过用户交互 获取用户的经纬度

Continue Read..

1.采用weiphp开发的

 

 

Application/Home/Controller/WeixinController.class.php  

文件 里面

//记录地址位置

if ($data['MsgType'] == 'event'  && $data['Event'] = 'LOCATION' ) {

$add['token'] = $w["token"] = $data ['ToUserName'];

$add['openid'] = $w["openid"] = $data ['FromUserName'];

$add['guiji'] = $data['Latitude'].",".$data['Longitude'].",".$data['Precision'];

$add['mTime'] = time();

$guiji = M("dd_guiji");

$row = $guiji->where($w)->find();

if(empty($row)){

$guiji->add($add);

}else{

$guiji->where($w)->save($add);

}

 

 

我新建了一个表来记录  当前用户 的经纬度  openid等

 

/**

*  说明: 根据两点间的经纬度计算距离

*  @param float $lat 纬度值

*  @param float $lng 经度值

*/

 function getDistance($lat1, $lng1, $lat2, $lng2) {

     $earthRadius = 6367000; 

 

     $lat1 = ($lat1 * pi() ) / 180;

     $lng1 = ($lng1 * pi() ) / 180;

 

     $lat2 = ($lat2 * pi() ) / 180;

     $lng2 = ($lng2 * pi() ) / 180;

 

     $calcLongitude = $lng2 - $lng1;

     $calcLatitude = $lat2 - $lat1;

     $stepOne = pow(sin($calcLatitude / 2), 2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude / 2), 2);  

     $stepTwo = 2 * asin(min(1, sqrt($stepOne)));

     $calculatedDistance = $earthRadius * $stepTwo;

 

     return round($calculatedDistance);

 }

/*

 * 根据客户openid 和配送人的Openid  查询二者之前的距离

 */

 

function getJuli($kehu_openid,$psr_openid){

$guiji = M("dd_guiji");

    $gj['kehu'] = $guiji->where(array("openid"=>$kehu_openid))->order("id desc")->find();

    $gj['peisongren'] = $guiji->where(array("openid"=>$psr_openid))->order("id desc")->find();

    

    

    $k = explode(",",$gj['kehu']['guiji']);

    $p = explode(",",$gj['peisongren']['guiji']);

    $a = getDistance($k[0], $k[1], $p[0], $p[1]);

//    $a = getDistance('39.916155', '116.396885', '39.910329', '116.396443');

    return $a;

    

    

}


 

 

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【微信】微信获取openid(必须要用服务号)

Continue Read..
//这里是在微信给用户推送消息的函数里面调用

$psurl = addons_url ( 'PeiSong://PeiSong/peisonglist/');
        $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf7f38b4a13482c18&redirect_uri=".$psurl ."&response_type=code&scope=snsapi_base&state=1#wechat_redirect";
        
        $content = "您有".count($ids)."条新的订单需要配送\n".date("Y-m-d H:i:s")."\n<a href='".$url."'>点击查看</a>";



//这里就是上面函数跳转的链接
虽然是用里面都写的php  但是这是个.html文件

<?php



$code = $_REQUEST['code'];
$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=wxf7f38b4a13482c18&secret=dd6aa3a6618ea6472a6abc1d42020e0d&code=$code&grant_type=authorization_code";

$res = https_request($url);
$result = json_decode($res, true);
function https_request($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;
}

$openid = $result['openid'];

?>



声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【微信】微信里面加播放器

Continue Read..
<iframe class="video_iframe" style="   z-index:1; " height="200" width="300" frameborder="0"  allowfullscreen="" src="http://v.qq.com/iframe/player.html?vid=w0135hxgaii&amp;width=300&amp;height=200&amp;auto=0"></iframe>

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权