瀏覽代碼

Merge branch 'test' of git.oschina.net:yiguanjia/php into test

洪海涛 8 年之前
父節點
當前提交
5fcbc269b5
共有 2 個文件被更改,包括 101 次插入1 次删除
  1. 55 0
      www/protected/components/CommonFn.php
  2. 46 1
      www/protected/modules/o2o/controllers/RechargeController.php

+ 55 - 0
www/protected/components/CommonFn.php

@@ -1096,4 +1096,59 @@ class CommonFn
         }
     }
 
+    public static function httpPost($url,$param,$post_file=false){
+        $oCurl = curl_init();
+        if(stripos($url,"https://")!==FALSE){
+            curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
+            curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);
+            curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
+        }
+        if (is_string($param)) {
+            $strPOST = $param;
+        } else {
+            $aPOST = array();
+            foreach($param as $key=>$val){
+                //$aPOST[] = $key."=".urlencode($val);
+            }
+            $strPOST =  join("&", $aPOST);
+
+        }
+
+        $this_header = array(
+            "content-type: application/x-www-form-urlencoded;
+            charset=UTF-8"
+        );
+        curl_setopt($oCurl,CURLOPT_HTTPHEADER,$this_header);
+        curl_setopt($oCurl, CURLOPT_URL, $url);
+        curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );
+        curl_setopt($oCurl, CURLOPT_POST,true);
+        curl_setopt($oCurl, CURLOPT_POSTFIELDS,$strPOST);
+        $sContent = curl_exec($oCurl);
+        $aStatus = curl_getinfo($oCurl);
+        curl_close($oCurl);
+        if(intval($aStatus["http_code"])==200){
+            return $sContent;
+        }else{
+            return false;
+        }
+    }
+
+
+    public static function sendWxMessage($data){
+        // 环境检查
+        $res = file_get_contents('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx9a632fd8918d1a48&secret=1d21b873c19a36b200cf1d0bb1e9aa26');
+
+        $access_token = json_decode($res,true)['access_token'];
+        $result = self::httpPost('https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$access_token,$data);
+        if ($result)
+        {
+            $json = json_decode($result,true);
+            if (!$json || !empty($json['errcode']) || $json['errcode']!=0) {
+                return false;
+            }
+            return $json;
+        }
+        return false;
+    }
+
 }

+ 46 - 1
www/protected/modules/o2o/controllers/RechargeController.php

@@ -4,6 +4,28 @@
  */
 class  RechargeController extends O2oBaseController{
     //充值卡 支付
+
+    public function actionTest(){
+
+        //$user = RUser::model()->get(new MongoId('57e238929f5160d6048b456d'));
+       // var_dump($user);exit;
+        $num = intval(ceil((rand(100000,999999)))/10000);
+
+        $data ='{
+                    "touser": "oTreyv4-5la34sYWyHTZ331wi6J8",
+                    "msgtype": "text",
+                    "text": {
+                    "content": "'.'恭喜您获得参与本次活动的权利,'.$num.'为您参加本活动的号码,'.'"
+                    }
+                }';
+
+        $result = 'asdf';
+
+        CommonFn::requestAjax(true,'success',json_decode($result),200,array());
+
+    }
+
+
     public function actionPayRecharge(){
         $user_id = Yii::app()->getRequest()->getParam("user_id");
         $pay_channel = Yii::app()->getRequest()->getParam("pay_channel");
@@ -29,7 +51,30 @@ class  RechargeController extends O2oBaseController{
         if($result === false){
             CommonFn::requestAjax(false,'支付遇到点问题了,请稍候再试');
         }else{
-            CommonFn::requestAjax(true,'success',json_decode($result),200,array());
+            //start充值活动暂用
+            if($order->price == 1000 ||$order->price == 5000){
+                $user = RUser::model()->get(new MongoId($user_id));
+                $num = intval(ceil((rand(100000,999999)))/10000);
+
+                $data ='{
+                    "touser": "'.$user->wx_pub_openid.'",
+                    "msgtype": "text",
+                    "text": {
+                    "content": "'.'恭喜您获得参与本次活动的权利,'.$num.'为您参加本活动的号码,'.'"
+                    }
+                }';
+
+                if(!empty(CommonFn::sendWxMessage($data))){
+                    CommonFn::requestAjax(true,'success',json_decode($result),200,array());
+                }
+
+            } else {
+                CommonFn::requestAjax(true,'success',json_decode($result),200,array());
+            }
+            //end
+
+
+
         }
     }