本文整理匯總了PHP中WxPayUnifiedOrder::SetMch_id方法的典型用法代碼示例。如果您正苦於以下問題:PHP WxPayUnifiedOrder::SetMch_id方法的具體用法?PHP WxPayUnifiedOrder::SetMch_id怎麽用?PHP WxPayUnifiedOrder::SetMch_id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類WxPayUnifiedOrder
的用法示例。
在下文中一共展示了WxPayUnifiedOrder::SetMch_id方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: unifiedOrder
/**
*
* 統一下單,WxPayUnifiedOrder中out_trade_no、body、total_fee、trade_type必填
* appid、mchid、spbill_create_ip、nonce_str不需要填入
* @param WxPayUnifiedOrder $inputObj
* @param int $timeOut
* @throws WxPayException
* @return 成功時返回,其他拋異常
*/
public static function unifiedOrder($inputObj, $timeOut = 6, $notify = '')
{
$url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
//檢測必填參數
if (!$inputObj->IsOut_trade_noSet()) {
throw new WxPayException("缺少統一支付接口必填參數out_trade_no!");
} else {
if (!$inputObj->IsBodySet()) {
throw new WxPayException("缺少統一支付接口必填參數body!");
} else {
if (!$inputObj->IsTotal_feeSet()) {
throw new WxPayException("缺少統一支付接口必填參數total_fee!");
} else {
if (!$inputObj->IsTrade_typeSet()) {
throw new WxPayException("缺少統一支付接口必填參數trade_type!");
}
}
}
}
//關聯參數
if ($inputObj->GetTrade_type() == "JSAPI" && !$inputObj->IsOpenidSet()) {
throw new WxPayException("統一支付接口中,缺少必填參數openid!trade_type為JSAPI時,openid為必填參數!");
}
if ($inputObj->GetTrade_type() == "NATIVE" && !$inputObj->IsProduct_idSet()) {
throw new WxPayException("統一支付接口中,缺少必填參數product_id!trade_type為JSAPI時,product_id為必填參數!");
}
//異步通知url未設置,則使用配置文件中的url
if (!$inputObj->IsNotify_urlSet()) {
$inputObj->SetNotify_url($notify);
//異步通知url
}
if ($inputObj->GetTrade_type() == 'APP') {
$inputObj->SetAppid(WxPayConfig::APP_APPID);
//開放平台APPID
$inputObj->SetMch_id(WxPayConfig::APP_MCHID);
//商戶平台商戶號
} else {
$inputObj->SetAppid(WxPayConfig::APPID);
//公眾賬號ID
$inputObj->SetMch_id(WxPayConfig::MCHID);
//商戶號
}
$inputObj->SetSpbill_create_ip($_SERVER['REMOTE_ADDR']);
//終端ip
//$inputObj->SetSpbill_create_ip("1.1.1.1");
$inputObj->SetNonce_str(self::getNonceStr());
//隨機字符串
//簽名
$inputObj->SetSign();
$xml = $inputObj->ToXml();
$startTimeStamp = self::getMillisecond();
//請求開始時間
$response = self::postXmlCurl($xml, $url, false, $timeOut);
$result = WxPayResults::Init($response);
self::reportCostTime($url, $startTimeStamp, $result);
//上報請求花費時間
return $result;
}
示例2: unifiedOrder
/**
*
* 統一下單,WxPayUnifiedOrder中out_trade_no、body、total_fee、trade_type必填
* appid、mchid、spbill_create_ip、nonce_str不需要填入
* @param WxPayUnifiedOrder $inputObj
* @param int $timeOut
* @throws WxPayException
* @return 成功時返回,其他拋異常
*/
public static function unifiedOrder($inputObj, $timeOut = 6)
{
$url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
$inputObj->SetAppid(APPID);
//公眾賬號ID
$inputObj->SetMch_id(MCHID);
//商戶號
$inputObj->SetSpbill_create_ip($_SERVER['REMOTE_ADDR']);
//終端ip
//$inputObj->SetSpbill_create_ip("1.1.1.1");
$inputObj->SetNonce_str(self::getNonceStr());
//隨機字符串
//簽名
$inputObj->SetSign();
$xml = $inputObj->ToXml();
$startTimeStamp = self::getMillisecond();
//請求開始時間
$response = self::postXmlCurl($xml, $url, false, $timeOut);
$result = WxPayResults::Init($response);
return $result;
}
示例3: pay_get
public function pay_get()
{
$order = I('get.order', '');
$m = M('orders');
// $map['from_member_id'] = $this->uid;
$map['order_number'] = $order;
// $map['status'] = 0;
$info = $m->where($map)->find();
if (empty($info)) {
//未支付訂單不存在
$this->error(5015);
}
$total = $info['total'] * 100;
$describe = 'testname';
require_once APP_PATH . "SDK/Payment/wechat/lib/WxPay.Api.php";
$input = new \WxPayUnifiedOrder();
//設置公眾賬號ID
$input->SetAppid(\WxPayConfig::APPID);
//設置商戶號
$input->SetMch_id(\WxPayConfig::MCHID);
//設置隨機字符串
$input->SetNonce_str(\WxPayApi::getNonceStr());
//設置商品描述
$input->SetBody($describe);
//設置商戶訂單號
$input->SetOut_trade_no($info['order_number']);
//設置總金額
$input->SetTotal_fee($total);
//設置終端IP
$input->SetSpbill_create_ip(get_client_ip());
//設置通知地址
$input->SetNotify_url(U('Wxpay/callback@api'));
//設置交易類型
$input->SetTrade_type('APP');
$order = \WxPayApi::unifiedOrder($input);
$this->success($order);
}
示例4: doMobileAjaxpay
public function doMobileAjaxpay()
{
global $_GPC, $_W;
load()->func('communication');
$fromopenid = $_GPC['fromopenid'];
$myopenid = $_W['openid'];
$num = 1;
$content = $_GPC['content'];
include_once '../addons/beauty_zhongchou/WxPay.Api.php';
$WxPayApi = new WxPayApi();
$input = new WxPayUnifiedOrder();
// $key=$this->module['config']['apikey'];//商戶支付秘鑰(API秘鑰)
$key = 'xLeBESmggiQMGpba2ieADmRQDlDPmIL8';
$account_info = pdo_fetch("select * from" . tablename('account_wechats') . "where uniacid={$_W['uniacid']}");
//身份標識(appid)
$appid = $account_info['key'];
//$mchid=$this->module['config']['mchid'];//微信支付商戶號(mchid)
$mchid = '1239385202';
$input->SetAppid($appid);
$input->SetMch_id($mchid);
$input->SetBody("test");
$input->SetAttach("test");
$input->SetOut_trade_no($mchid . date("YmdHis"));
$input->SetTotal_fee($num);
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis", time() + 600));
$input->SetGoods_tag("test");
$input->SetNotify_url("http://paysdk.weixin.qq.com/example/notify.php");
$input->SetTrade_type("JSAPI");
$input->SetOpenid($myopenid);
$result = $WxPayApi->unifiedOrder($input, 6, $key);
//隨機字符串
$chars = "abcdefghijklmnopqrstuvwxyz0123456789";
$str = "";
for ($i = 0; $i < 32; $i++) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
}
//簽名
$sign = $input->SetSign($key);
$data = array();
$data['pack'] = $result['prepay_id'];
$data['appId'] = $appid;
$data['timeStamp'] = TIMESTAMP;
$data['nonceStr'] = $str;
$data['signType'] = "MD5";
$data['paySign'] = $sign;
//生成訂單
// $data2 = array(
// 'uniacid' => $_W['uniacid'],
// 'openid' => $myopenid,
// 'ordersn' => date('Ymd').substr(time(), -5).substr(microtime(), 2, 5).sprintf('%02d', rand(0, 99)),
// 'content'=>$content,
// 'num' => $num,
// 'status' => 0,//訂單狀態,-1取消狀態,0普通狀態,1為已付款,2為已發貨,3為成功
// 'fromopenid'=>$fromopenid,
// 'content'=>
// 'createtime' => TIMESTAMP
// );
pdo_insert('beatuty_zhongchou_orders', $data2);
$orderid = pdo_insertid();
$order = pdo_fetch("SELECT * FROM " . tablename('beatuty_zhongchou_orders') . " WHERE id ={$orderid}");
$params['tid'] = $order['ordersn'];
$params['user'] = $_W['fans']['from_user'];
$params['fee'] = $order['num'];
$params['title'] = $_W['account']['name'];
$params['ordersn'] = $order['ordersn'];
$params['module'] = "beatuty_zhongchou";
//轉成json
$dataall = array('data' => $data, 'params' => $params);
return json_encode($dataall);
}
示例5: setbalance
//.........這裏部分代碼省略.........
//自定義訂單號,此處僅作舉例
$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("用戶充值");
$input->SetOut_trade_no($payment_api_log['id'] . "_" . time() . "_" . rand(0, 1000));
$input->SetAppid($payment_config['APPID']);
$input->SetMch_id($payment_config['MCHID']);
$input->SetTotal_fee($amt);
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis", time() + 600));
$input->SetGoods_tag("用戶充值");
$input->SetNotify_url('http://' . $host . $this->webroot . 'responds/weixin_balance');
$input->SetProduct_id($payment_api_log['id']);
$input->SetTrade_type("NATIVE");
$notify = new NativePay();
$result = $notify->GetPayUrl($input);
$code_url = isset($result["code_url"]) ? $result["code_url"] : '';
}
$this->set('wechatpay_type', $wechatpay_type);
$message = '';
$code = '1';
} catch (Exception $e) {
$message = '支付失敗,Caught exception: ' . $e->getMessage();
$code = '0';
}
} else {
//判斷支付方式是否存在
$payment['Payment']['code'] = strtolower($payment['Payment']['code']);
try {
$payment_config = unserialize($payment['Payment']['config']);
App::import('Vendor', 'payments/' . $payment['Payment']['code']);
$balance_payment = new $payment['Payment']['code']();
if ($payment['Payment']['is_online'] == 1) {
//在線支付增加api日誌
$payment_api_log = array('payment_code' => $payment['Payment']['code'], 'type' => 2, 'type_id' => $user_id, 'order_currency' => 'CHY', 'amount' => $this->data['pay']['money']);
$this->PaymentApiLog->save($payment_api_log);
//記錄支付日誌Id
$payment_api_log['id'] = $this->PaymentApiLog->id;
}
示例6: unifiedOrder
/**
*
* 統一下單,WxPayUnifiedOrder中out_trade_no、body、total_fee、trade_type必填
* appid、mchid、spbill_create_ip、nonce_str不需要填入
* @param WxPayUnifiedOrder $inputObj
* @param int $timeOut
* @throws WxPayException
* @return 成功時返回,其他拋異常
*/
public static function unifiedOrder($inputObj, $timeOut = 6)
{
$url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
//檢測必填參數
if (!$inputObj->IsOut_trade_noSet()) {
throw new WxPayException("缺少統一支付接口必填參數out_trade_no!");
} else {
if (!$inputObj->IsBodySet()) {
throw new WxPayException("缺少統一支付接口必填參數body!");
} else {
if (!$inputObj->IsTotal_feeSet()) {
throw new WxPayException("缺少統一支付接口必填參數total_fee!");
} else {
if (!$inputObj->IsTrade_typeSet()) {
throw new WxPayException("缺少統一支付接口必填參數trade_type!");
}
}
}
}
//關聯參數
if ($inputObj->GetTrade_type() == "JSAPI" && !$inputObj->IsOpenidSet()) {
throw new WxPayException("統一支付接口中,缺少必填參數openid!trade_type為JSAPI時,openid為必填參數!");
}
if ($inputObj->GetTrade_type() == "NATIVE" && !$inputObj->IsProduct_idSet()) {
throw new WxPayException("統一支付接口中,缺少必填參數product_id!trade_type為JSAPI時,product_id為必填參數!");
}
//異步通知url未設置,則使用配置文件中的url
if (!$inputObj->IsNotify_urlSet()) {
$inputObj->SetNotify_url(WxPayConfig::NOTIFY_URL);
//異步通知url
}
$inputObj->SetAppid(WxPayConfig::APPID);
//公眾賬號ID
$inputObj->SetMch_id(WxPayConfig::MCHID);
//商戶號
$inputObj->SetSpbill_create_ip($_SERVER['REMOTE_ADDR']);
//終端ip
//$inputObj->SetSpbill_create_ip("1.1.1.1");
$inputObj->SetNonce_str(self::getNonceStr());
//隨機字符串
//簽名
$inputObj->SetSign();
$xml = $inputObj->ToXml();
$startTimeStamp = self::getMillisecond();
//請求開始時間
$response = self::postXmlCurl($xml, $url, false, $timeOut);
$result = WxPayResults::Init($response);
// 統一下單接口返回正常的prepay_id,再按簽名規範重新生成簽名後,將數據傳輸給APP。
// 參與簽名的字段名為appId,partnerId,prepayId,nonceStr,timeStamp,package。注意:package的值格式為Sign=WXPay
$time_stamp = time();
$pack = 'Sign=WXPay';
//輸出參數列表
$prePayParams = array();
$prePayParams['appid'] = $result['appid'];
$prePayParams['partnerid'] = $result['mch_id'];
$prePayParams['prepayid'] = $result['prepay_id'];
$prePayParams['noncestr'] = $result['nonce_str'];
$prePayParams['package'] = $pack;
$prePayParams['timestamp'] = $time_stamp;
//echo json_encode($prePayParams);
$result = WxPayResults::InitFromArray($prePayParams, true)->GetValues();
self::reportCostTime($url, $startTimeStamp, $result);
//上報請求花費時間
return $result;
}
示例7: balance_deposit2
//.........這裏部分代碼省略.........
$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);
$input->SetAppid($payment_config['APPID']);
$input->SetMch_id($payment_config['MCHID']);
$input->SetTotal_fee($amt);
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis", time() + 600));
$input->SetGoods_tag($order_code);
$input->SetNotify_url('http://' . $host . $this->webroot . 'responds/weixin_notify');
$input->SetTrade_type("NATIVE");
$input->SetProduct_id($order_code);
$result = $notify->GetPayUrl($input);
$url2 = isset($result["code_url"]) ? $result["code_url"] : '';
$this->set('url2', $url2);
}
$this->set('order_code', $order_code);
$this->set('wechatpay_type', $wechatpay_type);
} else {
$pay_form_txt = "";
$host = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '');
if ($this->RequestHandler->isMobile() && $payment['Payment']['code'] == 'alipay') {
//手機支付寶支付訪問
$payment_api_log = array('payment_code' => $payment['Payment']['code'], 'type' => 1, 'type_id' => $orderid, 'order_id' => $order_code, 'order_currency' => 'CHY', 'amount' => $amount_money);
$this->PaymentApiLog->save($payment_api_log);
$alipay_config = array();
//合作身份者id,以2088開頭的16位純數字
$alipay_config['partner'] = isset($payment_config['partner']) ? $payment_config['partner'] : '';
//收款支付寶賬號,一般情況下收款賬號就是簽約賬號
$alipay_config['seller_id'] = isset($payment_config['partner']) ? $payment_config['partner'] : '';
//商戶的私鑰(後綴是.pen)文件相對路徑
$alipay_config['private_key_path'] = ROOT . '/vendors/payments/alipaywap/key/rsa_private_key.pem';
//支付寶公鑰(後綴是.pen)文件相對路徑
$alipay_config['ali_public_key_path'] = ROOT . '/vendors/payments/alipaywap/key/rsa_public_key.pem';
//簽名方式 不需修改
$alipay_config['sign_type'] = strtoupper('RSA');
//字符編碼格式 目前支持 gbk 或 utf-8