人人人妻人人人妻人人人,99精品国产综合久久久久五月天 ,欧美白人最猛性XXXXX,日韩AV无码免费播放

News新聞

業(yè)界新聞動態(tài)、技術前沿
Who are we?

您的位置:首頁      樂道系統(tǒng)FAQ      使用YII2框架實現(xiàn)微信公眾號中表單提交功能

使用YII2框架實現(xiàn)微信公眾號中表單提交功能

標簽: 發(fā)布日期:2017-09-04 00:00:00 268

剛接觸微信,要做一個在手機上的表單提交功能。

需求有這些:

  1. 只能在數(shù)據(jù)庫中存在的手機號看到表單。
  2. 表單可以重復提交。
  3. 第一次進入表單需要驗證
  4. 分享出去的頁面,別人進入后也需要驗證。

因為每個手機在同一個公眾號當中的openid是唯一性的。所以在手機查看這個表單頁面的時候,就將這個openid存到數(shù)據(jù)庫中,方便下次提交可以驗證。

下面是我的代碼。使用的是YII2框架。

Controller

//獲得回調函數(shù)
 public function actionCallback($code,$state){
    $model = new tp_tstz_proposal();
    $model1= new tp_tstz_staff();
    // 微信開放平臺網站應用的appid和秘鑰secret
    $appid = '';
    $secret = '';
    $curl = new curl\Curl();
    //獲取access_token
    $wxresponse = $curl->get('https://api.weixin.qq.com/sns/oauth2/access_token?appid=' . $appid
      . '&secret=' . $secret . '&code=' . $code . '&grant_type=authorization_code');
    $wxresult = json_decode($wxresponse);
    if(isset($wxresult->errcode) && $wxresult->errcode > 0){
      //分享出去,重新認證
     return $this->render('login');
      // 向微信請求授權時出錯,打印錯誤碼
      // echo json_encode($wxresult);
      // exit;
    }
    $openid=$wxresult->openid;
    $result=$model1::find()->where(['openid'=>$openid])->one();
    //如果OPENID存在就去表單
    if(count($result)>0){
      $key=123456;
      return $this->render('view',['model'=>$model,'key'=>$key]);
    }else{
      return $this->render('tel',['model'=>$model1,'openid'=> $openid]);
    }
  }`