예제 #1
0
<?php

$weixin = new WeixinAPI();
$user_info = $weixin->get_oauth_token();
$nonce_str = sha1(NONCE_KEY . $user_info->openid);
$timestamp = time();
if (isset($_GET['from_username'])) {
    $user = get_user_by('login', $_GET['from_username']);
    if (!$user) {
        exit('invalid invite username');
    }
    $invited_user_ids = get_user_meta($user->ID, 'invited_user_id');
    if ($current_user->ID !== $user->ID && !in_array($current_user->ID, $invited_user_ids)) {
        add_user_meta($user->ID, 'invited_user_id', $current_user->ID);
    }
}
if (isset($_POST['attend'])) {
    wp_update_user(array('ID' => $current_user->ID, 'user_email' => $_POST['email'], 'display_name' => $_POST['name']));
    update_user_meta($current_user->ID, 'phone', $_POST['phone']);
    update_user_meta($current_user->ID, 'attended', date('Y-m-d H:i:s'));
}
?>
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title><?php 
bloginfo('site_name');
?>
</title>
		<meta charset="utf-8">
예제 #2
0
    operation_fail("登陆失败");
}
$weixinAPI = new WeixinAPI();
$json = $weixinAPI->getOpenid($code);
session_start();
// 记录用户信息
$_SESSION['openid'] = $json['openid'];
$_SESSION['access_token'] = $json;
$openid = $json['openid'];
$home_url = '../index.php';
$account = Account::getAccount($json['openid']);
if ($account != null) {
    $_SESSION['account'] = $account;
    $extra = AccountExtra::getInfo($json['openid']);
    if ($extra != null) {
        $_SESSION['account_extra'] = $extra;
    }
} else {
    $weixinAPI = new WeixinAPI();
    $userInfo = $weixinAPI->getUserInfo($json['access_token'], $openid);
    Account::createAccount($openid, $userInfo['nickname']);
    $account = Account::getAccount($json['openid']);
    $_SESSION['account'] = $account;
}
//$home_url = '../h5/publish_task_page.php';
header('Location: ' . $home_url);
json_put("session", $_SESSION['access_token']);
json_output();
?>

예제 #3
0
<?php

/*
 * 微信API响应页面,用来处理来自微信的请求
 */
$wx = new WeixinAPI();
$wx->verify();
$wx->onmessage('event', function ($message) use($wx) {
    if ($message['EVENTKEY'] === 'COMING_SOON') {
        $wx->reply_message('艇好玩微信公众号8月底盛大发布,同时揭晓免费玩好艇的幸运玩家。', $message);
    }
});
예제 #4
0
<?php

$weixin = new WeixinAPI();
echo json_encode($weixin->refresh_menu());
 private function delivery_notify($order)
 {
     if (strcasecmp($order['payment'], 'wxpay') != 0) {
         return true;
     }
     $payment = M('b2c_payment')->where(array('token' => $this->token, 'branch_id' => $this->branch_id, 'pay_code' => 'wxpay'))->find();
     $wxpay_config = unserialize($payment['pay_config']);
     $wxuser = M('wxuser')->where(array('status' => 1, 'token' => $this->token))->find();
     $trade = M('b2c_wxtrade')->where(array('token' => $this->token, 'branch_id' => $this->branch_id, 'order_sn' => $order['sn']))->find();
     if (!empty($wxpay_config) && !empty($trade) && $wxuser['type'] == 1 && $wxuser['is_authed'] == 1) {
         require_once COMMON_PATH . '/WeixinAPI.php';
         $weixin = new WeixinAPI($wxuser['appid'], $wxuser['appsecret']);
         $access_token = $weixin->getAccessToken();
         import("@.ORG.LzWxPayHelper");
         $lzWxPayHelper = new LzWxPayHelper($wxpay_config);
         $ret = $lzWxPayHelper->delivernotify($access_token, $trade);
         return $ret;
     } else {
         Log::record('wxpay delivery type:' . $wxuser['type'] . ' auth:' . $wxuser['is_authed'] . ' config:' . print_r($wxpay_config, true), Log::INFO);
         Log::save();
     }
     return true;
 }
 function push_info($msg, $wx_user, $token)
 {
     $push = M('push_info');
     $info = $push->where(array('openid' => $msg['FromUserName'], 'wechat_id' => $msg['ToUserName']))->find();
     //获取appid和appsecret
     if (empty($info) || $info && floor((time() - $info['update_time']) / 86400) >= 1) {
         require_once COMMON_PATH . '/WeixinAPI.php';
         $weixin = new WeixinAPI($wx_user['appid'], $wx_user['appsecret']);
         $user = $weixin->getUserInfo($msg['FromUserName']);
         if (empty($info)) {
             $data = array('openid' => $msg['FromUserName'], 'wechat_id' => $msg['ToUserName'], 'content' => json_encode($user), 'create_time' => time(), 'update_time' => time());
             $push->add($data);
             $this->push_user_info(json_encode($this->signature($user)), $token);
         } elseif (floor((time() - $info['update_time']) / 86400) >= 1) {
             $data = array('content' => json_encode($user), 'update_time' => time());
             $this->push_user_info(json_encode($this->signature($user)), $token);
             $push->where(array('openid' => $msg['FromUserName'], 'wechat_id' => $msg['ToUserName']))->save($data);
         }
     }
 }
 function checkAccessToken($params = array())
 {
     require_once COMMON_PATH . '/WeixinAPI.php';
     $weixin = new WeixinAPI($params['appid'], $params['appsecret']);
     return $weixin->getAccessToken();
 }