public function oAuth() { $weObj = new \Org\Wechat\Wechat(C('WECHAT')); $access_token = $weObj->getOauthAccessToken(); if ($access_token) { $this->assign('openId', $access_token['openid']); $this->display($_GET['state']); } else { die('no access!'); } }
public function getVoucher($openId = null, $voucherId = 1) { $voucher = M('Voucher')->find($voucherId); if ($voucher == null) { $result['success'] = false; $result['message'] = '代金券获得已下线!'; $this->ajaxReturn($result); } else { $map['openId'] = $openId; $map['voucherId'] = $voucherId; $count = M('UserVoucher')->where($map)->count(); if ($count < $voucher['ulimit']) { $data['openId'] = $openId; $data['voucherId'] = $voucherId; $data['valid'] = 1; $data['ctime'] = time(); $id = M('UserVoucher')->data($data)->add(); $weObj = new \Org\Wechat\Wechat(C('WECHAT')); $message['touser'] = $openId; $message['template_id'] = 'ftB_fcU7tcQkx5he06K51e_DnB3ue_jrHF-pXywR-lw'; $message['url'] = 'http://www.meirixianguo.com/wechat/wxpay/order?showwxpaytitle=1'; $message['topcolor'] = '#00FF00'; $message['data']['first'] = array('value' => urlencode('您已经成功领取了一个果大侠代金券'), 'color' => '#000000'); $message['data']['keyword1'] = array('value' => '果大侠代金券-金额4.89元', 'color' => '#000000'); $message['data']['keyword2'] = array('value' => 100000 + $id, 'color' => '#000000'); $message['data']['keyword3'] = array('value' => date('Y-m-d'), 'color' => '#000000'); $message['data']['keyword4'] = array('value' => '永久', 'color' => '#000000'); $message['data']['remark'] = array('value' => urlencode('\\n现在就去定水果,还能分享给好友,一起开启健康生活!'), 'color' => '#FF8715'); $weObj->sendTemplateMessage($message); $result['success'] = true; $result['message'] = $voucher['description']; $this->ajaxReturn($result); } else { $result['success'] = false; $result['message'] = '您已达到代金券的上线!'; $this->ajaxReturn($result); } } }