private function sendOneMsg($item)
 {
     $ecid_cache = 'company_info' . $item['ecid'];
     if (!($companyInfo = S($ecid_cache))) {
         $companyInfo = $this->getCompanyInfo($item['ecid']);
     }
     if (!$companyInfo) {
         return false;
     }
     $options = array('token' => 'tokenaccesskey', 'appid' => $companyInfo['weixin_AppId'], 'appsecret' => $companyInfo['weixin_AppSecret']);
     $weObj = new Wechat($options);
     $msg = json_decode($item['content'], true);
     switch ($item['type']) {
         case '':
         case 'custom':
             if ($weObj->sendCustomMessage($msg)) {
                 $item['sendTime'] = date('Y-m-d H:i:s');
             }
             break;
         case 'templete':
             if ($weObj->sendTemplateMessage($msg)) {
                 $item['sendTime'] = date('Y-m-d H:i:s');
             }
             break;
         default:
             break;
     }
     $item['times']++;
     $m = M('Send_crontab');
     return $m->save($item);
 }
Esempio n. 2
0
 public static function getUserInfo()
 {
     // if($userInfo = session('userInfo')){
     //     return $userInfo;
     // }
     $companyInfo = self::getCompanyInfo();
     $options = array('token' => 'tokenaccesskey', 'appid' => $companyInfo['weixin_AppId'], 'appsecret' => $companyInfo['weixin_AppSecret']);
     $weixin = new Wechat($options);
     if ($userInfo = $weixin->getOauthAccessToken()) {
         $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}");
 }
Esempio n. 3
0
 private function sendOrderMsg($payQrcodeId, $openid, $logId)
 {
     $m = M('Company_pay_qrcode');
     $result = $m->find($payQrcodeId);
     $title = "您好,你的订单【{$result['name']}】已成功支付,请到工作人员处领取。";
     $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' => $openid, 'template_id' => '9vrZ54E2usz08SVYjManqdUlHlI--x3eMqWdXKBMwpI', 'url' => "http://www.icalex.com/Mobile/Exchange/payQrcode/openid/{$openid}/id/{$logId}", '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' => $result['price'] . '元', "color" => "#173177"), 'keyword3' => array('value' => '', "color" => "#173177"), 'keyword4' => array('value' => '', "color" => "#173177"), 'remark' => array('value' => "如有疑问,请拨打客服电话4009908355或在微信留言。!", "color" => "#173177")));
     $wechat = new \Org\Weixin\Wechat($options);
     $wechat->sendTemplateMessage($data);
 }
 public function index()
 {
     $companyInfo = $this->getCompanyInfo(888);
     $options = array('token' => 'tokenaccesskey', 'appid' => $companyInfo['weixin_AppId'], 'appsecret' => $companyInfo['weixin_AppSecret']);
     $weixin = new Wechat($options);
     $userInfo = $weixin->getOauthAccessToken();
     $type = I('get.t');
     if ($this->RedirectUrl($userInfo['openid'], 888)) {
         switch ($type) {
             case 'shop-index':
                 header("Location: http://www.icalex.com/Mobile/");
                 break;
             case 'shop-product':
                 header("Location: http://www.icalex.com/Mobile/Product");
                 break;
             case 'shop-car':
                 header("Location: http://www.icalex.com/Mobile/Order");
                 break;
             case 'exchangeQrcode':
                 $m = M('Company_pay_qrcode_paylog');
                 $result = $m->find(I('get.id'));
                 if (in_array($userInfo['openid'], C('ADMIN_OPENID'))) {
                     if ($result && !$result['exchangeSign']) {
                         $opt['exchangeSign'] = 1;
                         $opt['exchangeTime'] = date("Y-m-d H:i:s");
                         $opt['exchangeOpenId'] = $userInfo['openid'];
                         $opt['id'] = I('get.id');
                         if ($m->save($opt)) {
                             echo "<h1>success!</h1>";
                         }
                     } else {
                         echo "<h1>error!</h1>";
                     }
                 } else {
                     echo "<h1>no permission!</h1>";
                 }
                 break;
             default:
                 header("Location: http://www.icalex.com");
                 break;
         }
     }
 }
Esempio n. 5
0
 public function qrcodeNotify()
 {
     $weObj = new Wechat($this->getOption());
     if ($weObj->checkOrderSignature()) {
         $params = I('get.');
         $wecatMsg = $weObj->getRev()->getRevData();
         $this->log(2);
         if ($params['trade_state'] == 0) {
             $m = M('Company_pay_qrcode_paylog');
             $keyword = explode('_', $params['out_trade_no']);
             $save['payQrcodeId'] = $keyword[1];
             $save['openId'] = $wecatMsg['OpenId'];
             $save['payTime'] = date('Y-m-d H:i:s');
             $save['payInfo'] = serialize($params);
             $logId = $m->where($opt)->add($save);
             if ($wecatMsg['IsSubscribe'] == 1) {
                 $this->sendOrderMsg($save['payQrcodeId'], $wecatMsg['OpenId'], $logId);
             }
         }
         echo 'success';
     }
 }
Esempio n. 6
0
 private function getWechatUserInfo($openId)
 {
     //如果开通的不是高级版微防伪,直接返回
     if ($this->companyInfo['serviceId'] != 2) {
         return false;
     }
     //如果接口信息不完整,直接返回
     if ($this->companyInfo['weixin_AppId'] == '' || $this->companyInfo['weixin_AppSecret'] == '') {
         return false;
     }
     $weObj = new Wechat();
     if ($weObj->checkAuth($this->companyInfo['weixin_AppId'], $this->companyInfo['weixin_AppSecret'])) {
         $userInfo = $weObj->getUserInfo($openId);
         $userInfo['CreateTime'] = date("Y-m-d H:i:s", $userInfo['CreateTime']);
         if ($userInfo) {
             return $userInfo;
         }
     }
     return false;
 }
 private function sendMessage($option)
 {
     $options = array('appid' => 'wx043fe26d7171dc76', 'appsecret' => '9075a78a413ea5f12999e0fddcc2a60c');
     $data = array('touser' => $option['openId'], 'template_id' => 'MH6Vd2GxT_qG2VHhAduBMSDb-JNTp_GxkefrGt36-Wc', 'url' => "", 'topcolor' => '#000000', 'data' => array('first' => array('value' => "恭喜您成功获得 蒂罗尔微信商城{$option['ticket']}元代金券 一张。", "color" => "#173177"), 'keyword1' => array('value' => '代金券', "color" => "#173177"), 'keyword2' => array('value' => $option['exchangeCode'], "color" => "#173177"), 'keyword3' => array('value' => '2015-06-14', "color" => "#173177"), 'keyword4' => array('value' => '2015-08-14', "color" => "#173177"), 'remark' => array('value' => "", "color" => "#173177")));
     $wechat = new \Org\Weixin\Wechat($options);
     $wechat->sendTemplateMessage($data);
 }