$appid = ""; $secret = ""; $get_token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' . $appid . '&secret=' . $secret . '&code=' . $code . '&grant_type=authorization_code'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $get_token_url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); $res = curl_exec($ch); curl_close($ch); $json_obj = json_decode($res, true); $access_token = $json_obj['access_token']; $openid = $json_obj['openid']; /** For your local testing: */ $pm = new PropertyManager(); $dummy_openid = $pm->getDummyOpenid(); if (empty($openid) && isset($dummy_openid)) { $openid = $dummy_openid; } /** localhost test context END.*/ // Lottery logic if (isset($openid)) { $r = rand(0, 7); $gua = rand(0, 3); // Draw lottery. 抽奖放在这里 $wls = new WechatLotteryService(); // Today's drawing time. 第几次抽奖 $today_time = $wls->save_onelot($openid); $rewardDao = new RewardDao(); $reward_row = $rewardDao->getByOpenid($openid); if ($today_time == WechatLotteryService::OVER_LIMIT) {