示例#1
0
 public static function getUserInfo()
 {
     $companyInfo = self::getCompanyInfo();
     $options = array('token' => 'tokenaccesskey', 'appid' => $companyInfo['weixin_AppId'], 'appsecret' => $companyInfo['weixin_AppSecret']);
     $weixin = new TPWechat($options);
     $userInfo = $weixin->getOauthAccessToken();
     if ($userInfo) {
         $m = M("Company_888_user_info");
         $opt['openId'] = $userInfo['openid'];
         $result = $m->where($opt)->find();
         if ($result) {
             session('userInfo', $result);
             return $result;
         } else {
             $id = $m->add($opt);
             $opt['id'] = $id;
             session('userInfo', $opt);
             return $opt;
         }
     }
     if (I('get.redirct') == 1) {
         return '';
     }
     $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'] . '&redirct=1';
     $url = urlencode($url);
     $redirctUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$companyInfo['weixin_AppId']}&redirect_uri={$url}&response_type=code&scope=snsapi_base&state=0#wechat_redirect";
     header("Location: {$redirctUrl}");
 }
示例#2
0
 public static function getMedia($mediaId)
 {
     $appid = C('WECHAT_APPID');
     $appsecret = C('WECHAT_SECRET');
     $options = array('appid' => $appid, 'appsecret' => $appsecret);
     $weixin = new TPWechat($options);
     return $weixin->getMedia($mediaId);
 }
 public function invitationGet()
 {
     $openid = I('get.u');
     $companyInfo = $this->getCompanyInfo();
     $options = array('token' => 'tokenaccesskey', 'appid' => $companyInfo['weixin_AppId'], 'appsecret' => $companyInfo['weixin_AppSecret']);
     $weixin = new TPWechat($options);
     if (!$openid) {
         $oauthToken = $weixin->getOauthAccessToken();
         if (!$oauthToken) {
             $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
             //$url = urlencode($url);
             $redirctUrl = $weixin->getOauthRedirect($url, '', 'snsapi_base');
             header("Location: {$redirctUrl}");
         }
         $openid = $oauthToken['openid'];
     }
     $this->assign('openid', $openid);
     $auth = $weixin->checkAuth();
     $api_ticket = $weixin->getJsTicket();
     $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     $js_sign = $weixin->getJsSign($url);
     $time = time();
     $card_id = 'pk0Ius992-phYJGSJLG2dJfBuFvw';
     $this->assign('card_id', $card_id);
     $signature = new Signature();
     $signature->add_data($api_ticket);
     $signature->add_data($card_id);
     $signature->add_data(strval($time));
     $this->assign('card_signature', $signature->get_signature());
     $this->assign('js_sign', $js_sign);
     $this->assign('tm', $time);
     $this->assign('api_ticket', $api_ticket);
     $this->display();
 }
示例#4
0
 private function getQrPicUrl($ecid, $sceneId)
 {
     $m = M("Company_info");
     $opt['company_ecid'] = $ecid;
     $token = $m->where($opt)->find();
     //如果接口信息不完整,直接返回
     if ($token['weixin_AppId'] == '' || $token['weixin_AppSecret'] == '') {
         return;
     }
     $weObj = new \Org\Weixin\TPWechat();
     if ($weObj->checkAuth($token['weixin_AppId'], $token['weixin_AppSecret'])) {
         $qrCode = $weObj->getQRCode($sceneId, 0);
         if ($qrCode) {
             return $weObj->getQRUrl($qrCode['ticket']);
         }
     }
 }
示例#5
0
 private function sendShareMsg($openid, $prize = '')
 {
     $companyInfo = $this->getCompanyInfo();
     $options = array('appid' => $companyInfo['weixin_AppId'], 'appsecret' => $companyInfo['weixin_AppSecret'], 'partnerid' => $companyInfo['weixin_PartnerID'], 'partnerkey' => $companyInfo['weixin_PartnerKey'], 'paysignkey' => $companyInfo['weixin_PaySignKey']);
     if ($prize) {
         $prize = '恭喜您获得({$prize})一个';
     } else {
         $prize = '感谢参与!';
     }
     $data = array('touser' => $openid, 'template_id' => 'tuan_68XdmLt57-J_k0Au3Qw7Y_Hh3uUdjclzcuhbcA', 'url' => '', 'topcolor' => '#000000', 'data' => array('first' => array('value' => '感谢您参加分享抽奖活动', "color" => "#173177"), 'keyword1' => array('value' => '蒂罗尔全新升级…八重惊喜等你来', "color" => "#173177"), 'keyword2' => array('value' => date('Y-m-d H:i:s'), "color" => "#173177"), 'remark' => array('value' => $prize, "color" => "#173177")));
     $wechat = new TPWechat($options);
     $wechat->sendTemplateMessage($data);
 }
示例#6
0
 private function getJsSdkPrams()
 {
     $weObj = new TPWechat(array('appid' => 'wx043fe26d7171dc76', 'appsecret' => '9075a78a413ea5f12999e0fddcc2a60c'));
     $auth = $weObj->checkAuth();
     $api_ticket = $weObj->getJsTicket();
     $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     $js_sign = $weObj->getJsSign($url);
     return $js_sign;
 }
示例#7
0
 private function sendOrderMsg($orderInfo)
 {
     $uid = $orderInfo['uId'];
     $m = M('Company_888_user_info');
     $userInfo = $m->find($uid);
     $goods = json_decode($orderInfo['goods'], true);
     dump($goods);
     for ($i = 0; $i < count($goods); $i++) {
         if ($i > 0) {
             $goodsText .= ',';
         }
         $goodsText .= "{$goods[$i]['name']}({$goods[$i]['type']}) * {$goods[$i]['num']}";
     }
     $address = json_decode($orderInfo['address'], true);
     $title = "您好,你的订单【{$orderInfo['orderNo']}】已成功支付,我们将尽快处理。";
     if ($userInfo) {
         $companyInfo = $this->getCompanyInfo();
         $options = array('appid' => $companyInfo['weixin_AppId'], 'appsecret' => $companyInfo['weixin_AppSecret'], 'partnerid' => $companyInfo['weixin_PartnerID'], 'partnerkey' => $companyInfo['weixin_PartnerKey'], 'paysignkey' => $companyInfo['weixin_PaySignKey']);
         $data = array('touser' => $userInfo['openId'], 'template_id' => 'GtKtiZJnnt98LYKpdo6Pu6_4o1CkkGbyjdr5GuVpy9o', 'url' => '', 'topcolor' => '#000000', 'data' => array('first' => array('value' => $title, "color" => "#173177"), 'keyword1' => array('value' => date('Y-m-d H:i:s'), "color" => "#173177"), 'keyword2' => array('value' => (int) $orderInfo['price'] + (int) $orderInfo['expressPrice'] . '元', "color" => "#173177"), 'keyword3' => array('value' => $goodsText, "color" => "#173177"), 'keyword4' => array('value' => $address['tel'], "color" => "#173177"), 'keyword5' => array('value' => $address['province'] . $address['city'] . $address['district'] . $address['address'], "color" => "#173177"), 'remark' => array('value' => "如有疑问,请拨打客服电话4009633517或添加微信客服 lp87170871”", "color" => "#173177")));
         $wechat = new TPWechat($options);
         $wechat->sendTemplateMessage($data);
     }
 }
示例#8
0
 public function index()
 {
     $weObj = new TPWechat($this->getOption());
     //验证合法性
     $weObj->valid();
     //获取微信参数
     $this->wechatMsg = $weObj->getRev()->getRevData();
     //回复内容
     $response = '';
     // //检查是否具有调用权限
     $code = $this->checkCompany($weObj->getRevTo(), $weObj->getRevContent());
     if ($code != Error::SUCCESS_OK) {
         echo Error::getErrMsg($code);
         return;
     }
     //添加用户
     $this->saveUserInfo($this->companyInfo['ecid'], $this->wechatMsg['FromUserName']);
     //处理收到的信息
     switch ($this->wechatMsg['MsgType']) {
         case TPWechat::MSGTYPE_TEXT:
             //收到文本信息
             $keywordResponse = new \Weixin\Keyword\KeywordResponse($this->companyInfo, $this->wechatMsg);
             $response = $keywordResponse->getResponse();
             break;
         case TPWechat::MSGTYPE_EVENT:
             //收到事件信息
             $eventResponse = new \Weixin\Event\EventResponse($this->companyInfo, $this->wechatMsg);
             $response = $eventResponse->getResponse();
             break;
         case TPWechat::MSGTYPE_LOCATION:
             //收到地理信息
             $locationResponse = new \Weixin\Location\LocationResponse($this->companyInfo, $this->wechatMsg);
             $response = $locationResponse->getResponse();
             break;
         case TPWechat::MSGTYPE_IMAGE:
             //回复图片信息
             break;
         case TPWechat::MSGTYPE_VOICE:
             //处理语音信息
             if (assert($this->wechatMsg['Recognition'])) {
                 $keywordResponse = new \Weixin\Keyword\KeywordResponse($this->companyInfo, $this->wechatMsg);
                 $response = $keywordResponse->getResponse();
             }
             break;
         default:
             break;
     }
     // 响应回复
     switch ($response['type']) {
         case TPWechat::MSGTYPE_TEXT:
             $weObj->text($response["content"])->reply();
             break;
         case TPWechat::MSGTYPE_NEWS:
             $weObj->news($response['content'])->reply();
         default:
             $weObj->transfer_customer_service()->reply();
             break;
     }
     if ($response['ext'] != null) {
         $this->sendCustomMessage($response['ext'], $this->wechatMsg['FromUserName']);
     }
     // 记录日志
     $wechatMsg['Content'] = htmlspecialchars_decode($wechatMsg['Content']);
     //过滤html和实体
     $wechatMsg['Content'] = strip_tags($wechatMsg['Content']);
     \Weixin\Log\ResponseLog::wxReceiveLog($this->companyInfo['ecid'], $this->wechatMsg);
 }