示例#1
0
}
if ($_GP['isok'] == '1') {
    message('支付成功!', WEBSITE_ROOT . mobile_url('myorder'), 'success');
}
$payment = mysqld_select("SELECT * FROM " . table('payment') . " WHERE  enabled=1 and code='weixin' limit 1");
$configs = unserialize($payment['configs']);
$settings = globaSetting(array("weixin_appId", "weixin_appSecret"));
$_CMS['weixin_pay_appid'] = $settings['weixin_appId'];
//受理商ID,身份标识
$_CMS['weixin_pay_mchId'] = $configs['weixin_pay_mchId'];
//商户支付密钥Key。审核通过后,在微信发送的邮件中查看
$_CMS['weixin_pay_paySignKey'] = $configs['weixin_pay_paySignKey'];
//JSAPI接口中获取openid,审核后在公众平台开启开发模式后可查看
$_CMS['weixin_pay_appSecret'] = $settings['weixin_appSecret'];
include_once "WxPayPubHelper/WxPayPubHelper.php";
$weixin_openid = get_weixin_openid();
//=========步骤2:使用统一支付接口,获取prepay_id============
//使用统一支付接口
$unifiedOrder = new UnifiedOrder_pub();
//设置统一支付接口参数
//设置必填参数
//appid已填,商户无需重复填写
//mch_id已填,商户无需重复填写
//noncestr已填,商户无需重复填写
//spbill_create_ip已填,商户无需重复填写
//sign已填,商户无需重复填写
$unifiedOrder->setParameter("openid", $weixin_openid);
//商品描述
$unifiedOrder->setParameter("body", $goodtitle);
//商品描述
//自定义订单号,此处仅作举例
示例#2
0
 function xoauth($appid, $secret)
 {
     global $_GP;
     //用户不授权返回提示说明
     if ($_GP['code'] == "authdeny") {
         exit;
     }
     //高级接口取未关注用户Openid
     if (isset($_GP['code'])) {
         if (empty($appid) || empty($secret)) {
             message('微信公众号没有配置公众号AppId和公众号AppSecret!');
         }
         $state = $_GP['state'];
         //0未获取用户资料 1获取用户资料
         //查询活动时间
         $code = $_GP['code'];
         $oauth2_code = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . $appid . "&secret=" . $secret . "&code=" . $code . "&grant_type=authorization_code";
         $content = http_get($oauth2_code);
         $token = @json_decode($content, true);
         if (empty($token) || !is_array($token) || empty($token['access_token']) || empty($token['openid'])) {
             message('获取微信公众号授权失败,公众平台返回原始数据为:' . $content['meta']);
             exit;
         }
         $from_user = $token['openid'];
         $access_token = get_weixin_token();
         $oauth2_url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $access_token . "&openid=" . $from_user . "&lang=zh_CN";
         $content = http_get($oauth2_url);
         $info = @json_decode($content, true);
         if ($info['subscribe'] == 1) {
             $follow = 1;
         } else {
             $follow = 0;
         }
         $fans = mysqld_select("SELECT * FROM " . table('weixin_wxfans') . " WHERE weixin_openid=:weixin_openid ", array(':weixin_openid' => $from_user));
         $gender = $info["gender"];
         $nickname = $info["nickname"];
         if (empty($fans) || empty($fans['weixin_openid']) || empty($fans["nickname"])) {
             if ($follow == 0 && $state == 0) {
                 get_weixin_openid(1);
                 return;
             }
             if ($follow == 0 && $state == 1) {
                 $access_token = $token['access_token'];
                 $oauth2_url = "https://api.weixin.qq.com/sns/userinfo?access_token=" . $access_token . "&openid=" . $from_user . "&lang=zh_CN";
                 $content = http_get($oauth2_url);
                 $info = @json_decode($content, true);
             }
             if (empty($info) || !is_array($info) || empty($info['openid'])) {
                 message('获取微信公众号授权失败[无法取得info], 请稍后重试');
                 exit;
             }
             $gender = $info['sex'];
             $nickname = $info["nickname"];
         }
         if (empty($fans['weixin_openid'])) {
             $row = array('nickname' => $nickname, 'follow' => $follow, 'gender' => intval($gender), 'weixin_openid' => $from_user, 'avatar' => '', 'createtime' => TIMESTAMP);
             mysqld_insert('weixin_wxfans', $row);
             if (!empty($info["headimgurl"])) {
                 mysqld_update('weixin_wxfans', array('avatar' => $info["headimgurl"]), array('weixin_openid' => $from_user));
             }
         } else {
             $row = array('follow' => $follow, 'gender' => intval($gender), 'avatar' => '');
             if (!empty($nickname)) {
                 $row['nickname'] = $nickname;
             }
             mysqld_update('weixin_wxfans', $row, array('weixin_openid' => $from_user));
             if (!empty($info["headimgurl"])) {
                 mysqld_update('weixin_wxfans', array('avatar' => $info["headimgurl"]), array('weixin_openid' => $from_user));
             }
         }
         if (!empty($fans['openid']) && !empty($nickname)) {
             $member = mysqld_select("SELECT realname FROM " . table('member') . " WHERE openid=:openid ", array(':openid' => $fans['openid']));
             if (empty($member['realname'])) {
                 mysqld_update('member', array('realname' => $nickname), array('openid' => $fans['openid']));
             }
         }
         return $from_user;
     } else {
         message('微信端网页授权域名设置出错!');
         exit;
     }
 }