$packetParams['out_trade_no'] = $out_trade_no; //总金额 $packetParams['total_fee'] = $total_fee; //访问接口IP //$packetParams['spbill_create_ip'] = Request::getClientIp(); $packetParams['spbill_create_ip'] = '127.0.0.1'; //接受微信支付异步通知回调地址 $packetParams['notify_url'] = ecmobile_url() . $notify_url; //交易类型:JSAPI,NATIVE,APP $packetParams['trade_type'] = "APP"; //签名 TODO $sign = $reqHandler->createMd5Sign($packetParams); $packetParams['sign'] = $sign; $time_stamp = strval(time()); //获取prepayid $prepayid = $reqHandler->sendPrepay($packetParams); if ($prepayid != null) { $pack = 'Sign=WXPay'; //输出参数列表 $prePayParams = array(); $prePayParams['appid'] = $APP_ID; $prePayParams['partnerid'] = $PARTNER; $prePayParams['prepayid'] = $prepayid; $prePayParams['package'] = $pack; $prePayParams['noncestr'] = $nonce_str; $prePayParams['timestamp'] = $time_stamp; //生成签名 $sign = $reqHandler->createMd5Sign($prePayParams); $outparams['error_code'] = 0; $outparams['succeed'] = 1; $outparams['error_desc'] = 'ok';
$signParams = array(); $signParams['appid'] = $APP_ID; $signParams['appkey'] = $APP_KEY; $signParams['noncestr'] = $nonce_str; $signParams['package'] = $package; $signParams['timestamp'] = $time_stamp; $signParams['traceid'] = 'mytraceid_001'; //生成支付签名 $sign = $reqHandler->createSHA1Sign($signParams); //增加非参与签名的额外参数 $signParams['sign_method'] = 'sha1'; $signParams['app_signature'] = $sign; //剔除appkey unset($signParams['appkey']); //获取prepayid $prepayid = $reqHandler->sendPrepay($signParams); if ($prepayid != null) { $pack = 'Sign=WXPay'; //输出参数列表 $prePayParams = array(); $prePayParams['appid'] = $APP_ID; $prePayParams['appkey'] = $APP_KEY; $prePayParams['noncestr'] = $nonce_str; $prePayParams['package'] = $pack; $prePayParams['partnerid'] = $PARTNER; $prePayParams['prepayid'] = $prepayid; $prePayParams['timestamp'] = $time_stamp; //生成签名 $sign = $reqHandler->createSHA1Sign($prePayParams); $outparams['retcode'] = 0; $outparams['retmsg'] = 'ok';
/** * 微信支付 */ public function wechatAction() { $babyId = $this->devices->getBabyIdByShoeId($this->userInfo['uid'], $this->_sanReq['shoe_id']); if (!$babyId) { $this->_showMsg(self::NON_SHOE, $this->di['flagmsg'][self::NON_SHOE]); } //角色名 if (!empty($rel) && $rel['family_rolename'] != '') { $rolename = $rel['family_rolename']; } else { $rolename = ''; } //获取套餐 $renew = $this->renew->getRenew($serviceId, 1); if (!$renew) { $this->_showMsg(self::NON_PACKAGE, $this->di['flagmsg'][self::NON_PACKAGE]); } //订单号 $orderNo = (string) Common::makeOrderSn(); //生成续费订单,入库 if (($res = $this->renew->renewUpdate($shoeId, $this->userInfo['uid'], $serviceId, $_SERVER['REQUEST_TIME'], 1, $orderNo, 3, $renew['cr_real_price'], $renew['cr_name'], $renew['cr_period'], $renew['cr_coins'], $rolename, $babyId['baby_id'], $babyId['dev_imei'])) != self::SUCCESS) { $this->_showMsg($res, $this->di['flagmsg'][$res]); } include_once __DIR__ . '/../../utils/wechat/classes/RequestHandler.class.php'; include_once __DIR__ . '/../../utils/wechat/tenpay_config.php'; include __DIR__ . '/../../utils/wechat/classes/client/TenpayHttpClient.class.php'; //获取token值 $reqHandler = new RequestHandler(); //配置 $wechatConf = $this->di->get('sysconfig')['payment']['wechat']; $reqHandler->init($wechatConf['app_id'], $wechatConf['app_secret'], $wechatConf['partner_key'], $wechatConf['app_key']); $Token = $reqHandler->GetToken(); if ($Token != '') { //设置package支付参数 $packageParams = array(); $packageParams['bank_type'] = 'WX'; //支付类型 $packageParams['body'] = $renew['cr_name']; //商品描述 $packageParams['fee_type'] = '1'; //银行币种 $packageParams['input_charset'] = 'UTF-8'; //字符集 renewServer $packageParams['notify_url'] = $this->di->get['sysconfig']['renewServer'] . $wechatConf['notify_url']; //通知地址 $packageParams['out_trade_no'] = $orderNo; //商户订单号 $packageParams['partner'] = $wechatConf['partner']; //设置商户号 $packageParams['spbill_create_ip'] = $_SERVER['REMOTE_ADDR']; //支付机器IP $packageParams['total_fee'] = $renew['cr_real_price'] * 100; //商品总金额,以分为单位 $package = $reqHandler->genPackage($packageParams); $time_stamp = (string) time(); $nonce_str = md5(rand()); //设置支付参数 $signParams = array(); $signParams['appid'] = $APP_ID; $signParams['appkey'] = $APP_KEY; $signParams['noncestr'] = $nonce_str; $signParams['package'] = $package; $signParams['timestamp'] = $time_stamp; $signParams['traceid'] = 'yunduo_wechat'; //生成支付签名 $sign = $reqHandler->createSHA1Sign($signParams); //增加非参与签名的额外参数 $signParams['sign_method'] = 'sha1'; $signParams['app_signature'] = $sign; //剔除appkey unset($signParams['appkey']); //获取prepayid $prepayid = $reqHandler->sendPrepay($signParams); if ($prepayid != null) { $pack = 'Sign=WXPay'; //输出参数列表 $prePayParams = array(); $prePayParams['appid'] = $APP_ID; $prePayParams['appkey'] = $APP_KEY; $prePayParams['noncestr'] = $nonce_str; $prePayParams['package'] = $pack; $prePayParams['partnerid'] = $PARTNER; $prePayParams['prepayid'] = $prepayid; $prePayParams['timestamp'] = $time_stamp; //生成签名 $sign = $reqHandler->createSHA1Sign($prePayParams); $outparams['retcode'] = '0'; $outparams['retmsg'] = 'ok'; $outparams['partnerid'] = $PARTNER; $outparams['noncestr'] = $nonce_str; $outparams['package'] = $pack; $outparams['prepayid'] = $prepayid; $outparams['timestamp'] = $time_stamp; $outparams['sign'] = $sign; //增加返回相关产品信息 $outparams['order_no'] = $orderNo; $outparams['order_subject'] = $renew['cr_name']; $outparams['total_fee'] = $renew['cr_real_price']; $this->_returnResult(array('flag' => self::SUCCESS, 'data' => $outparams)); } else { $this->_showMsg(self::FAILED_GET_PREPAYID, $this->di['flagmsg'][self::FAILED_GET_PREPAYID]); } } else { $this->_showMsg(self::FAILED_GET_TOKEN, $this->di['flagmsg'][self::FAILED_GET_TOKEN]); } }