本文整理汇总了PHP中WxPayUnifiedOrder::SetKey方法的典型用法代码示例。如果您正苦于以下问题:PHP WxPayUnifiedOrder::SetKey方法的具体用法?PHP WxPayUnifiedOrder::SetKey怎么用?PHP WxPayUnifiedOrder::SetKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WxPayUnifiedOrder
的用法示例。
在下文中一共展示了WxPayUnifiedOrder::SetKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setbalance
public function setbalance()
{
//登录验证
$this->checkSessionUser();
$this->layout = 'default_full';
//引入模版
$this->pageTitle = $this->ld['user_deposit'] . ' - ' . $this->configs['shop_title'];
Configure::write('debug', 0);
$this->loadModel('PaymentApiLog');
if (!empty($_GET['code']) && !empty($_GET['other_data'])) {
$other_data_str = $_GET['other_data'];
$other_data_arr = explode("_", $other_data_str);
$payment_api_id = isset($other_data_arr[2]) ? $other_data_arr[2] : 0;
$payment_log_info = $this->PaymentApiLog->find('first', array('conditions' => array('PaymentApiLog.id' => $payment_api_id)));
$this->data['pay']['money'] = isset($other_data_arr[1]) ? $other_data_arr[1] : 0;
$this->data['pay']['payment_type'] = isset($other_data_arr[0]) ? $other_data_arr[0] : 0;
}
if ($this->RequestHandler->isPost() || isset($this->data['pay'])) {
if (isset($this->data)) {
$this->data = $this->clean_xss($this->data);
}
$pay_url = '';
$message = '操作失败';
$code = '0';
if (isset($this->data['pay']) && !empty($this->data['pay'])) {
$this->data['pay']['payment_type'] = intval($this->data['pay']['payment_type']);
$this->data['pay']['money'] = floatval($this->data['pay']['money']);
$payment = $this->Payment->find('first', array('conditions' => array('Payment.id' => $this->data['pay']['payment_type'], 'Payment.status' => '1')));
if (isset($payment) && !empty($payment)) {
//用户Id
$user_id = $_SESSION['User']['User']['id'];
//获取用户信息
$user_info = $this->User->find('first', array('conditions' => array('User.id' => $user_id)));
//定义路径
$host = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '');
$this->set('payment_code', $payment['Payment']['code']);
if ($payment['Payment']['code'] == 'weixinpay') {
$payment_amount = $this->data['pay']['money'];
$amount_money = $payment_amount;
//在线支付增加api日志
$payment_api_log = array('id' => isset($payment_log_info['PaymentApiLog']['id']) ? $payment_log_info['PaymentApiLog']['id'] : 0, 'payment_code' => $payment['Payment']['code'], 'type' => 2, 'type_id' => $user_id, 'order_currency' => 'CHY', 'amount' => $payment_amount);
$this->PaymentApiLog->save($payment_api_log);
$payment_api_log['id'] = $this->PaymentApiLog->id;
$payment_config = unserialize($payment['Payment']['config']);
$amt = $amount_money * 100;
try {
$wechatpay_type = false;
if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
App::import('Vendor', 'Weixinpay', array('file' => 'WxPayPubHelper.php'));
$jsApi = new JsApi_pub($payment_config['APPID'], $payment_config['MCHID'], $payment_config['KEY'], $payment_config['APPSECRET']);
if (empty($_GET['code'])) {
$request_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$other_data = $this->data['pay']['payment_type'] . "_" . $this->data['pay']['money'] . "_" . $payment_api_log['id'];
$request_url .= "?other_data=" . $other_data;
//触发微信返回code码
$wechat_pay_url = $jsApi->createOauthUrlForCode($request_url);
Header("Location: {$wechat_pay_url}");
} else {
//获取code码,以获取openid
$code = $_GET['code'];
$jsApi->setCode($code);
$openid = $jsApi->getOpenId();
}
if (!empty($openid)) {
$unifiedOrder = new UnifiedOrder_pub($payment_config['APPID'], $payment_config['MCHID'], $payment_config['KEY'], $payment_config['APPSECRET']);
$unifiedOrder->setParameter("openid", "{$openid}");
//商品描述
$unifiedOrder->setParameter("body", "用户充值[金额:" . $payment_amount . "]");
//商品描述
//自定义订单号,此处仅作举例
$timeStamp = time();
$out_trade_no = $payment_api_log['id'];
$unifiedOrder->setParameter("out_trade_no", "{$out_trade_no}");
//商户订单号
$unifiedOrder->setParameter("total_fee", $amt);
//总金额
$unifiedOrder->setParameter("notify_url", 'http://' . $host . $this->webroot . 'responds/weixin_balance');
//通知地址
$unifiedOrder->setParameter("trade_type", "JSAPI");
//交易类型
$prepay_id = $unifiedOrder->getPrepayId();
$jsApi->setPrepayId($prepay_id);
$jsApiParameters = $jsApi->getParameters();
if (!empty($jsApiParameters)) {
$json_result = json_decode($jsApiParameters);
$code_url = isset($json_result->paySign) ? $jsApiParameters : '';
}
} else {
throw new SDKRuntimeException("支付失败,OpenId 获取失败");
}
} else {
Configure::write('debug', 0);
$this->layout = 'ajax';
$wechatpay_type = true;
App::import('Vendor', 'Weixinpay', array('file' => 'WxPay.Api.php'));
App::import('Vendor', 'Phpqcode', array('file' => 'phpqrcode.php'));
$input = new WxPayUnifiedOrder();
$input->SetKey($payment_config['KEY']);
$input->SetBody("用户充值[金额:" . $payment_amount . "]");
$input->SetAttach("用户充值");
//.........这里部分代码省略.........
示例2: balance_deposit2
/**
*函数balance_deposit 用于资金存放.
*/
public function balance_deposit2()
{
$this->pageTitle = '支付 - ' . $this->configs['shop_title'];
if (!empty($_GET['code']) && !empty($_GET['other_data'])) {
$other_data_str = $_GET['other_data'];
$other_data_arr = explode("_", $other_data_str);
$_POST['amount_num'] = isset($other_data_arr[0]) ? $other_data_arr[0] : 0;
$_POST['payment_id'] = isset($other_data_arr[1]) ? $other_data_arr[1] : 0;
$_POST['invoice'] = isset($other_data_arr[2]) ? $other_data_arr[2] : 0;
$_POST['item_name'] = isset($other_data_arr[3]) ? $other_data_arr[3] : 0;
}
if (!isset($_POST['amount_num']) || !($_POST['amount_num'] > 0) || !isset($_POST['payment_id']) || !($_POST['payment_id'] > 0)) {
die('参数错误');
}
$orderid = $_POST['invoice'];
$order_code = $_POST['item_name'];
if (constant('Product') == 'AllInOne') {
$orfo = $this->Order->find('first', array('conditions' => array('Order.id' => $orderid)));
if (!empty($orfo)) {
$orfo['Order']['sub_pay'] = $_POST['payment_id'];
$this->Order->save($orfo['Order']);
}
}
$modified = date('Y-m-d H:i:s');
$user_id = $_SESSION['User']['User']['id'];
$user_info = $this->User->findbyid($user_id);
$user_money = $user_info['User']['balance'] + $_POST['amount_num'];
$amount_money = $_POST['amount_num'];
$payment_id = $_POST['payment_id'];
$payment = $this->Payment->find('first', array('conditions' => array('Payment.id' => $payment_id)));
$this->Cookie->write('pay_type', $payment_id);
$account_info = array('user_id' => $user_id, 'amount' => $amount_money, 'payment' => $payment_id, 'status' => 0);
$this->UserAccount->save($account_info);
$account_id = $this->UserAccount->id;
$order_id = isset($_SESSION['order']['ever_id']) ? $_SESSION['order']['ever_id'] : $account_id;
$host = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '');
try {
$payment_config = unserialize($payment['Payment']['config']);
if ($payment['Payment']['code'] == "weixinpay") {
$this->layout = 'default';
$amt = $amount_money * 100;
$wechatpay_type = false;
if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
App::import('Vendor', 'Weixinpay', array('file' => 'WxPayPubHelper.php'));
$jsApi = new JsApi_pub($payment_config['APPID'], $payment_config['MCHID'], $payment_config['KEY'], $payment_config['APPSECRET']);
if (empty($_GET['code'])) {
$request_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$other_data = $amount_money . "_" . $payment_id . "_" . $orderid . "_" . $order_code;
$request_url .= "?other_data=" . $other_data;
//触发微信返回code码
$wechat_pay_url = $jsApi->createOauthUrlForCode($request_url);
Header("Location: {$wechat_pay_url}");
} else {
//获取code码,以获取openid
$code = $_GET['code'];
$jsApi->setCode($code);
$openid = $jsApi->getOpenId();
}
if (!empty($openid)) {
$unifiedOrder = new UnifiedOrder_pub($payment_config['APPID'], $payment_config['MCHID'], $payment_config['KEY'], $payment_config['APPSECRET']);
$unifiedOrder->setParameter("openid", $openid);
//商品描述
$unifiedOrder->setParameter("body", $order_code);
//商品描述
//自定义订单号,此处仅作举例
$timeStamp = time();
$out_trade_no = $order_code;
$unifiedOrder->setParameter("out_trade_no", "{$out_trade_no}");
//商户订单号
$unifiedOrder->setParameter("total_fee", $amt);
//总金额
$unifiedOrder->setParameter("notify_url", 'http://' . $host . $this->webroot . 'responds/weixin_notify');
//通知地址
$unifiedOrder->setParameter("trade_type", "JSAPI");
//交易类型
$prepay_id = $unifiedOrder->getPrepayId();
$jsApi->setPrepayId($prepay_id);
$jsApiParameters = $jsApi->getParameters();
if (!empty($jsApiParameters)) {
$json_result = json_decode($jsApiParameters);
$code_url = isset($json_result->paySign) ? $jsApiParameters : '';
$this->set('url2', $code_url);
}
} else {
throw new SDKRuntimeException("支付失败,OpenId 获取失败");
}
} else {
$this->layout = "ajax";
$wechatpay_type = true;
App::import('Vendor', 'Weixinpay', array('file' => 'WxPay.Api.php'));
App::import('Vendor', 'Phpqcode', array('file' => 'phpqrcode.php'));
$input = new WxPayUnifiedOrder();
$notify = new NativePay();
$input->SetKey($payment_config['KEY']);
$input->SetBody($order_code);
$input->SetAttach($order_code);
$input->SetOut_trade_no($order_code);
//.........这里部分代码省略.........