微信服务器故障下的重复请求

w

0-需对微信服务器的返回值进行异常处理;

1-营销分享奖励的身份标识;

2-暂时将安全性限制转移给ua和微信服务器,必须获取微信服务器返回的openId,顾客才可以进行浏览全站网页。

codeigniter index.php

<?php
if (!isset($_REQUEST['cid']) || empty($_REQUEST['cid'])) {
    require_once 'wtmpconfig/wconfig.php';
    $wxwid = $wcofig['wxwid'];
    $wxws = $wcofig['wxws'];
    $wphpself = base64_encode($_SERVER['PHP_SELF']);
    $wphpself = substr($wphpself, 0, strlen($wphpself) - 2);
    $wxurl = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' . $wxwid . '&redirect_uri=http://' . $_SERVER['HTTP_HOST'] . '/?wphpself=' . $wphpself . '&response_type=code&scope=snsapi_base&state=0#wechat_redirect';

    if (!isset($_REQUEST['wphpself'])) header('Location: ' . $wxurl);

    $wxr_state = intval($_REQUEST['state']);
    $wxr_code = $_REQUEST['code'];
    if (!empty($wxr_code)) {
        $wxurl = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' . $wxwid
            . '&secret=' . $wxws . '&code=' . $wxr_code . '&grant_type=authorization_code';
        $result = file_get_contents($wxurl);
        $res = json_decode($result, true);
        $wxr_openid = trim($res['openid']);
        $wphp_go = $_SERVER['HTTP_HOST'] . base64_decode(($_REQUEST['wphpself'] . '=='));
        $wphp_go = trim(str_replace('index.php/', '', $wphp_go));

        if (!empty($wxr_openid)) $wphp_go = trim('http://' . $wphp_go . '?cid=' . $wxr_openid);
        header('Location: ' . $wphp_go);
    }
}

define('WXCID', $_REQUEST['cid']);
原文地址:https://www.cnblogs.com/rsapaper/p/6473472.html