当前位置: 首页>>代码示例>>PHP>>正文


PHP Wechat::createPackageXml方法代码示例

本文整理汇总了PHP中Wechat::createPackageXml方法的典型用法代码示例。如果您正苦于以下问题:PHP Wechat::createPackageXml方法的具体用法?PHP Wechat::createPackageXml怎么用?PHP Wechat::createPackageXml使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Wechat的用法示例。


在下文中一共展示了Wechat::createPackageXml方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: pay

 public function pay()
 {
     $totalprice = $_GET['totalprice'];
     //$cart_names = $_GET['cart_name'];
     //$openid = $_GET['uid'];
     $openid = $_SESSION['uid'];
     $orderid = $_GET['orderid'];
     $agent = $_SERVER['HTTP_USER_AGENT'];
     if (!strpos($agent, "Android")) {
         $this->assign("tbtspic", "ios.png");
     } else {
         $this->assign("tbtspic", "android.png");
     }
     if (!strpos($agent, "icroMessenger")) {
         $alipay = M("Alipay")->find();
         $url = 'http://' . $_SERVER['SERVER_NAME'] . __ROOT__ . '/api/wapalipay/alipayapi.php?WIDseller_email=' . $alipay['alipayname'] . '&WIDout_trade_no=' . $orderid . '&WIDsubject=' . $orderid . '&WIDtotal_fee=' . $totalprice;
         header("Location: {$url}");
         exit;
     }
     import('Wechat', APP_PATH . 'Common/Wechat', '.class.php');
     $config = M("Wxconfig")->where(array("id" => "1"))->find();
     $options = array('token' => $config["token"], 'encodingaeskey' => $config["encodingaeskey"], 'appid' => $config["appid"], 'appsecret' => $config["appsecret"], 'partnerid' => $config["partnerid"], 'partnerkey' => $config["partnerkey"], 'paysignkey' => $config["paysignkey"]);
     $weObj = new Wechat($options);
     if (strlen($openid) <= 10) {
         $info = $weObj->getOauthAccessToken();
         if (!$info) {
             $callback = 'http://' . $_SERVER['SERVER_NAME'] . U("App/Index/pay", $_GET);
             $url = $weObj->getOauthRedirect($callback, '', 'snsapi_base');
             header("Location: {$url}");
             exit;
         } else {
             $openid = $info['openid'];
         }
     }
     $order_info = M('Order')->where(array('orderid' => $orderid))->find();
     if (empty($order_info)) {
         exit('订单信息错误');
     }
     $cartdata = json_decode($order_info['cartdata'], true);
     $cart_name = $cartdata[0]['name'];
     $cart_num = $cartdata[0]['num'];
     $cart_price = $cartdata[0]['price'];
     $cart_goods_id = $cartdata[0]['id'];
     $goodsdata = M("Good")->where(array("id" => $cart_goods_id))->find();
     $userdata = M("User")->where(array("uid" => $_SESSION['uid']))->find();
     if (empty($userdata)) {
         exit('用户信息错误');
     }
     $username = $userdata['username'];
     $phone = $userdata['phone'];
     $address = $userdata['address'];
     $this->assign("goodsdata", $goodsdata);
     $this->assign("username", $username);
     $this->assign("phone", $phone);
     $this->assign("address", $address);
     $this->assign("cart_name", $cart_name);
     $this->assign("cart_num", $cart_num);
     $this->assign("cart_price", $cart_price);
     $coptions = array('token' => $config["token"], 'encodingaeskey' => $config["encodingaeskey"], 'appid' => $config["cappid"], 'appsecret' => $config["cappsecret"], 'partnerid' => $config["partnerid"], 'partnerkey' => $config["partnerkey"], 'paysignkey' => $config["paysignkey"]);
     $cweObj = new Wechat($coptions);
     $cinfo = $cweObj->getOauthAccessToken();
     if (!$cinfo) {
         $callback = 'http://' . $_SERVER['SERVER_NAME'] . U("App/Index/pay", $_GET);
         $url = $cweObj->getOauthRedirect($callback, '', 'snsapi_base');
         header("Location: {$url}");
         exit;
     }
     $appid = $coptions['appid'];
     $mch_id = $coptions['partnerid'];
     $out_trade_no = $orderid;
     $body = $cart_name;
     $total_fee = $cart_price * $cart_num * 100;
     $notify_url = 'http://' . $_SERVER['SERVER_NAME'];
     $spbill_create_ip = $_SERVER["REMOTE_ADDR"];
     $nonce_str = $cweObj->generateNonceStr();
     $copenid = $cinfo['openid'];
     $pay_xml = $cweObj->createPackageXml($appid, $mch_id, $nonce_str, $body, $out_trade_no, $total_fee, $spbill_create_ip, $notify_url, $copenid);
     $pay_xml = $cweObj->get_pay_id($pay_xml);
     if ($pay_xml['err_code'] == "ORDERPAID") {
         $this->redirect('App/Index/payover', array('out_trade_no' => $out_trade_no, 'uid' => $_SESSION['uid']));
         eixt();
     }
     $prepay_id = $pay_xml['prepay_id'];
     $jsApiObj["appId"] = $appid;
     $timeStamp = time();
     $jsApiObj["timeStamp"] = "{$timeStamp}";
     $jsApiObj["nonceStr"] = $nonce_str;
     $jsApiObj["package"] = "prepay_id={$prepay_id}";
     $jsApiObj["signType"] = "MD5";
     $jsApiObj["paySign"] = $cweObj->getPaySignature($jsApiObj);
     $url = json_encode($jsApiObj);
     $returnUrl = 'http://' . $_SERVER['SERVER_NAME'] . U('App/Index/payover', array('out_trade_no' => $out_trade_no, 'uid' => $_SESSION['uid']));
     $info = R("Api/Api/gettheme");
     C("DEFAULT_THEME", $info["theme"]);
     $this->assign("price", $cart_price * $cart_num);
     $this->assign("info", $info);
     $this->assign("url", $url);
     $this->assign("returnUrl", $returnUrl);
     $this->display();
 }
开发者ID:zhezhisama,项目名称:zz,代码行数:100,代码来源:IndexAction.class.php


注:本文中的Wechat::createPackageXml方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。