Micro-channel public number to log (test number)

1.https://mp.weixin.qq.com/advanced/advanced?action=dev&t=advanced/dev&token=614565808&lang=zh_CN

Basic settings token verification 

define("TOKEN", "fmyinpin123456");
        $echoStr = $_GET["echostr"];
        //valid signature , option
        if(WechatCallbackApiTest::checkSignature()){
            echo $echoStr;
            exit;
        }

<?php
/**
 * Created by Fm.
 * User: Arvin
 * Date: 2019/1/21
 * Time: 15:00
 */

namespace app\api\libs;


class WechatCallbackApiTest
{

    public function responseMsg()
    {
        //get post data, May be due to the different environments
        $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];

        //extract post data
        if (!empty($postStr)){

            $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
            $fromUsername = $postObj->FromUserName;
            $toUsername = $postObj->ToUserName;
            $keyword = trim($postObj->Content);
            $time = time();
            $textTpl = "<xml>
                            <ToUserName><![CDATA[%s]]></ToUserName>
                            <FromUserName><![CDATA[%s]]></FromUserName>
                            <CreateTime>%s</CreateTime>
                            <MsgType><![CDATA[%s]]></MsgType>
                            <Content><![CDATA[%s]]></Content>
                            <FuncFlag>0</FuncFlag>
                            </xml>";
            if(!empty( $keyword ))
            {
                $msgType = "text";
                $contentStr = "Welcome to wechat world!";
                $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
                echo $resultStr;
            }else{
                echo "Input something...";
            }

        }else {
            echo "";
            exit;
        }
    }

    public static function checkSignature()
    {
        $signature = $_GET["signature"];
        $timestamp = $_GET["timestamp"];
        $nonce = $_GET["nonce"];

        $token = TOKEN;
        $tmpArr = array($token, $timestamp, $nonce);
        sort($tmpArr);
        $tmpStr = implode( $tmpArr );
        $tmpStr = sha1( $tmpStr );

        if( $tmpStr == $signature ){
            return true;
        }else{
            return false;
        }
    }
}

2.https://mp.weixin.qq.com/cgi-bin/settingpage?t=setting/function&action=function&token=614565808&lang=zh_CN

Callback settings page authoritative name

3.https://mp.weixin.qq.com/cgi-bin/frame?t=advanced/dev_tools_frame&nav=10049&token=614565808&lang=zh_CN

Public platform test number set above

Interface Configuration / Modify

JS interface security domain / modification

Web page authorized to obtain information about users / modification

  public function index(){
        $appid =$this->appid;
        $redirect_uri = urlencode($this->redirect_uri);
        $url ="https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$appid."&redirect_uri=".$redirect_uri."&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
        header("Location:".$url);
        exit;
    }

    public function http_curl($url,$type='get',RES $ = 'JSON', $ ARR = '' ) 
    { 
        // 1. Initialization curl 
        $ CH = curl_init ();
         // 2. curl setting parameters of 
        curl_setopt ( $ CH , CURLOPT_URL to, $ URL ); 
        curl_setopt ( $ CH , CURLOPT_SSL_VERIFYPEER, to false ); // do not verify the certificate 
        curl_setopt ( $ CH , CURLOPT_SSL_VERIFYHOST, to false ); // do not verify the certificate 
        curl_setopt ( $ CH , CURLOPT_RETURNTRANSFER,. 1 );
         IF ( $ type == 'POST') {
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $arr);
        }
        //3.采集
        $output = curl_exec($ch);
        //4.关闭
        curl_close($ch);
        if ($res == 'json') {
            return json_decode($output, true);
        }
    }

    //
    public function getUserOpentId(){
        //Callback address returns a code, then we go get openid and authorization acquired access_token according to code 
        $ code = $ _GET [ 'code' ];
         $ AppID = $ the this -> AppID;
         $ Secret = $ the this -> appsecret;
         url $ = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=." $ AppID . "= & Secret." $ Secret . "& code =." $ code . "& grant_type = authorization_code" ;
         $ RES = $ the this -> http_curl ( $ URL );
         $ the access_token = $ RES [ 'the access_token'];
        $getopenid = $res['openid'];
        //获取用户授权信息
        $urltoc = "https://api.weixin.qq.com/sns/userinfo?access_token=".$access_token."&openid=".$getopenid."&lang=zh_CN";
        $resinfos = $this->http_curl($urltoc);
        print_r($res);
        print_r($resinfos);
        die;
        $openid = $resinfos['openid'];
        $check_member = Db::name("member")->where('openid',OpenID $ ) -> Find ();
         IF ( empty ( $ check_member )) {
             // first entered, the user information is acquired, into the database 
            $ resInfo [ 'OpenID'] = $ OpenID ;
             $ insert_data = [
                 'OpenID' => OpenID $ , 
                'the create_time' => Time () 
            ]; 
            Db :: name ( "Member") -> INSERT ( $ insert_data );
             $ the userId = Db :: name ( 'Member') -> getLastInsID (); 
            the Session : : set ( 'wx_member_info',$ resinfo);
             $ The this -> the redirect ( 'Home / index / the index_html' ); 
        } the else {
             // note is already a member of the public numbers, the user calls the information stored in the session to 
            $ wx_member_info = :: Db name ( 'Member' ) -> WHERE ( "OpenID", $ OpenID ) -> Find (); 
            the Session :: SET ( 'wx_member_info', $ wx_member_info );
             $ the this -> the redirect ( 'Home / index / the index_html' ); 
        } 
    }

 

Guess you like

Origin www.cnblogs.com/wxtrip/p/10973979.html