| 1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
- namespace addons\HuifuPay\common\service;
- use yii\db\Exception;
- use \Yii;
- class WechatService
- {
- public function getOpenId($code)
- {
- $wechatModel = \Yii::$app->wechat;
- if (!$wechatModel->isWechat) throw new Exception('不是微信请求');
- $resultData = $wechatModel->miniProgram->auth->session($code);
- $openid = $resultData["openid"];
- return $openid;
- }
- public function getScheme($params)
- {
- $wechatModel = \Yii::$app->wechat;
- $accessToken= $wechatModel->miniProgram->access_token->getToken(true);
- $url1 = 'https://api.weixin.qq.com/wxa/generatescheme?access_token='.$accessToken['access_token'];
- $ch = curl_init();
- $data1 = array("path"=>$params['path'], "query"=>$params['query'],"env_version"=>"release");
- // if(isset($params["env_version"]))
- // {
- // array_merge($data1,["env_version"=>"trial"]);
- // }
- $data = json_encode(array("expire_type"=>1,"expire_interval"=>5,"jump_wxa"=>$data1));
- curl_setopt($ch, CURLOPT_URL, $url1);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $output = curl_exec($ch);
- curl_close($ch);
- return json_decode($output,true);
- }
- }
|