<?php
//接口调试地址可以查看错误信息
//https://mp.weixin.qq.com/debug/cgi-bin/apiinfo?t=index&type=%E5%9F%BA%E7%A1%80%E6%94%AF%E6%8C%81&form=%E8%8E%B7%E5%8F%96access_token%E6%8E%A5%E5%8F%A3%20/token
//本人测试用的是smarty框架(low)
//公众号测试请先在公众平台-基本设置-IP白名单中设置本机测试的IP地址白名单
//include('includes/global.php');
$appid = "";
$appsecret = "";
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret";
//$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf0e81c3bee622d60&redirect_uri=http%3A%2F%2Fnba.bluewebgame.com%2Foauth_response.php&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect ";
$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_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$jsoninfo = json_decode($output, true);
$access_token = $jsoninfo["access_token"];
$url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=$access_token";
$result = https_request($url);
$jsoninfo = json_decode($result); // 默认false,为Object,若是True,为Array
$data = $jsoninfo -> data;
$arr = $data -> openid; // 获得所有用户的Openid
$temp = 0;
while ($temp < count($arr)) {
$openid = $arr[$temp];
getInfo($access_token,$openid);
$temp++;
}
// 根据Openid获取单个用户信息,如nickname
function getInfo($access_token,$openid){
$url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=$access_token&openid=$openid&lang=zh_CN";
$output = https_request($url);
$jsoninfo = json_decode($output);
//echo $jsoninfo -> headimgurl;
//echo $jsoninfo -> nickname;
//echo $jsoninfo -> nickname;
print_r($jsoninfo) ;
echo "<br>";
}
function https_request($url)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($curl);
if (curl_errno($curl)) {return 'ERROR '.curl_error($curl);}
curl_close($curl);
return $data;
}
function pay(){
ini_set('date.timezone','Asia/Shanghai');
Vendor('Weipay.lib.WxPayApi');
Vendor('Weipay.lib.WxPayNativePay');
Vendor('Weipay.lib.log');
$notify = new \NativePay();
$url1 = $notify->GetPrePayUrl("123456789");
$input = new \WxPayUnifiedOrder();
$input->SetBody("test");
$input->SetAttach("test");
$input->SetOut_trade_no(\WxPayConfig::MCHID.date("YmdHis"));
$input->SetTotal_fee("1");
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis", time() + 600));
$input->SetGoods_tag("test");
$input->SetNotify_url("http://buriedsoul.cn/qidian/index.php/Home/Pay/payed
");
$input->SetTrade_type("NATIVE");
$input->SetProduct_id("123456789");
// $result = $notify->GetPrePayUrl($input);
$url1 = $notify->GetPrePayUrl($input);
$url2 = $result["code_url"];
}
//print_r($jsoninfo);
//Tr("商户查询","title");
//Ts("register.htm");
?>