JsApiPay::GetOpenidFromMp PHP Method

GetOpenidFromMp() public method

通过code从工作平台获取openid机器access_token
public GetOpenidFromMp ( string $code ) : openid
$code string 微信跳转回来带上的code
return openid
    public function GetOpenidFromMp($code)
    {
        $url = $this->__CreateOauthUrlForOpenid($code);
        //初始化curl
        $ch = curl_init();
        //设置超时
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        if (WxPayConfig::CURL_PROXY_HOST != "0.0.0.0" && WxPayConfig::CURL_PROXY_PORT != 0) {
            curl_setopt($ch, CURLOPT_PROXY, WxPayConfig::CURL_PROXY_HOST);
            curl_setopt($ch, CURLOPT_PROXYPORT, WxPayConfig::CURL_PROXY_PORT);
        }
        //运行curl,结果以jason形式返回
        $res = curl_exec($ch);
        curl_close($ch);
        //取出openid
        $data = json_decode($res, true);
        $this->data = $data;
        $openid = $data['openid'];
        return $openid;
    }

Usage Example

コード例 #1
0
ファイル: wxpay_openid.php プロジェクト: vincentgy/rubys
 public function index()
 {
     //echo "one";
     $this->load->library('wxpayexception');
     //echo "two";
     define('APPID', $this->config->get('wxpay_appid'));
     define('MCHID', $this->config->get('wxpay_mchid'));
     define('KEY', $this->config->get('wxpay_key'));
     define('APPSECRET', $this->config->get('wxpay_appsecret'));
     define('SSLCERT_PATH', DIR_SYSTEM . 'helper/wxpay_api/apiclient_cert.pem');
     define('SSLKEY_PATH', DIR_SYSTEM . 'helper/wxpay_api/apiclient_key.pem');
     define('CURL_PROXY_HOST', '0.0.0.0');
     define('CURL_PROXY_PORT', 0);
     define('REPORT_LEVENL', 1);
     //echo "three";
     $this->load->library('wxpaydata');
     //echo "four";
     $this->load->library('wxpayapi');
     //echo "five";
     $this->load->library('wxpayjsapipay');
     $tools = new JsApiPay();
     $openId = $tools->GetOpenidFromMp($_GET['code']);
     $this->session->data['weixin_openid'] = $openId;
     //echo $this->session->data['redirect'];
     //echo "微信支付测试中......";
     //exit;
     $url = $this->url->link('checkout/checkout', '', 'SSL');
     header("Location: {$url}");
     //exit();
     //$this->response->redirect(str_replace('&', '&', $this->sesssion->data['redirect']));
 }
All Usage Examples Of JsApiPay::GetOpenidFromMp