<commit_before><?php

define('WX_APPID','');
define('WX_APPSECRET','');
function wechat_oauth(){
    $code = $_GET['code'];
    $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . WX_APPID . "&secret=" . WX_APPSECRET . "&code=" . $code . "&grant_type=authorization_code";
    $content = oauth_http('get',$array(),$url,'');
    $ss = json_decode($content,true);
    $info_url = 'https://api.weixin.qq.com/sns/userinfo?access_token=' . $ss['access_token'] . '&openid=' . $ss['openid'];
    $user_info = oauth_http('get',$array(),$info_url,'');
    $weixin_id = $user_info["unionid"];
    if(is_user_logged_in()){
        $this_user = wp_get_current_user();
        update_user_meta($this_user->ID ,"weixin_uid",$weixin_id);
        //update_user_meta($this_user->ID ,"weixin_access_token",$weixin_access_token);
        echo '<script>if( window.opener ) {window.opener.location.reload();
						window.close();
						}else{
						window.location.reload()";
						}</script>';
    }else{
        $oauth_user = get_users(array("meta_key "=>"weixin_uid","meta_value"=>$weixin_id));
        if(is_wp_error($oauth_user) || !count($oauth_user)){
            $username = $user_info["nickname"];
            $login_name = wp_create_nonce($weixin_id);
            $random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
            $userdata=array(
                'user_login' => $login_name,
                'display_name' => $username,
                'user_pass' => <PASSWORD>,
                'nick_name' => $username
            );
            $user_id = wp_insert_user( $userdata );
            wp_signon(array("user_login"=>$login_name,"user_password"=>$random_password),false);
            update_user_meta($user_id ,"weixin_uid",$weixin_id);
            echo '<script>if( window.opener ) {window.opener.location.reload();
						window.close();
						}else{
						window.location.href = "'.home_url('/me/setting?2').'";
						}</script>';

        }else{
            //update_user_meta($oauth_user[0]->ID ,"weixin_access_token",$sina_access_token);
            wp_set_auth_cookie($oauth_user[0]->ID);
            echo '<script>if( window.opener ) {window.opener.location.reload();
						window.close();
						}else{
						window.location.href = "'.home_url('/me/setting?2').'";
						}</script>';
        }
    }
}

function wechat_oauth_url(){
    $_SESSION ['state'] = md5 ( uniqid ( rand (), true ) );
    $appkey = '';
    $url = 'https://open.weixin.qq.com/connect/qrconnect?appid='. WX_APPID .'&redirect_uri='. urlencode (home_url('/type=wechat')) .'&response_type=code&scope=snsapi_login&state=' . $_SESSION ['state'] . '#wechat_redirect'
	return $url;
}<commit_msg>add wechat<commit_after><?php

define('WX_APPID','');
define('WX_APPSECRET','');

function wechat_oauth(){
    $code = $_GET['code'];
    $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . WX_APPID . "&secret=" . WX_APPSECRET . "&code=" . $code . "&grant_type=authorization_code";
    $content = oauth_http('get',$array(),$url,'');
    $ss = json_decode($content,true);
    $info_url = 'https://api.weixin.qq.com/sns/userinfo?access_token=' . $ss['access_token'] . '&openid=' . $ss['openid'];
    $user_info = oauth_http('get',$array(),$info_url,'');
    $weixin_id = $user_info["unionid"];
    if(is_user_logged_in()){
        $this_user = wp_get_current_user();
        update_user_meta($this_user->ID ,"weixin_uid",$weixin_id);
        echo '<script>if( window.opener ) {window.opener.location.reload();
						window.close();
						}else{
						window.location.reload()";
						}</script>';
    }else{
        $oauth_user = get_users(array("meta_key "=>"weixin_uid","meta_value"=>$weixin_id));
        if(is_wp_error($oauth_user) || !count($oauth_user)){
            $username = $user_info["nickname"];
            $login_name = wp_create_nonce($weixin_id);
            $random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
            $userdata=array(
                'user_login' => $login_name,
                'display_name' => $username,
                'user_pass' => $<PASSWORD>,
                'nick_name' => $username
            );
            $user_id = wp_insert_user( $userdata );
            wp_signon(array("user_login"=>$login_name,"user_password"=>$<PASSWORD>),false);
            update_user_meta($user_id ,"weixin_uid",$weixin_id);
            echo '<script>if( window.opener ) {window.opener.location.reload();
						window.close();
						}else{
						window.location.href = "' . home_url() . '";
						}</script>';

        }else{
            wp_set_auth_cookie($oauth_user[0]->ID);
            echo '<script>if( window.opener ) {window.opener.location.reload();
						window.close();
						}else{
						window.location.href = "'.home_url('/me/setting?2').'";
						}</script>';
        }
    }
}

function social_oauth_wechat(){
    if (isset($_GET['code']) && isset($_GET['type']) && $_GET['type'] == 'wechat'){
        wechat_oauth();
    }
}
add_action('init','social_oauth_wechat')

function wechat_oauth_url(){
    $_SESSION ['state'] = md5 ( uniqid ( rand (), true ) );
    $appkey = '';
    $url = 'https://open.weixin.qq.com/connect/qrconnect?appid='. WX_APPID .'&redirect_uri='. urlencode (home_url('/type=wechat')) .'&response_type=code&scope=snsapi_login&state=' . $_SESSION ['state'] . '#wechat_redirect'
	return $url;
}
{'fraction_non_alphanumeric': 0.19176319176319176, 'fraction_numerical': 0.002574002574002574, 'mean_word_length': 3.2170542635658914, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 40, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3649733', 'n_tokens_mistral': 2061, 'n_tokens_neox': 1919, 'n_words': 236}