作者 chencheng

kaquan-1

... ... @@ -28,9 +28,10 @@ class Wechat extends Api
1.前端获取jsjdk的配置
*/
public function get_jsjdk_config(){
if(empty(request()->param('store_id'))){return $this->error('门店信息错误');}
try{
$param = request()->param();
$app = WehcatModule::getInstance()->initWechat();
$app = WehcatModule::getInstance(request()->param('store_id'))->initWechat();
$app->jssdk->setUrl($param['url']);
$APIs = ['updateAppMessageShareData','updateTimelineShareData','onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','onMenuShareWeibo','onMenuShareQZone','chooseWXPay','openLocation','getLocation'];
$config = $app->jssdk->buildConfig($APIs, true);
... ... @@ -162,13 +163,11 @@ class Wechat extends Api
public function get_user_info_by_code (){
$user_id = 0;
if(empty(request()->param('code'))){
return $this->error('非法操作');
}
if(empty(request()->param('code'))){return $this->error('非法操作');}
if(empty(request()->param('store_id'))){return $this->error('门店信息错误');}
try{
$app = WehcatModule::getInstance()->initWechat();
$app = WehcatModule::getInstance(request()->param('store_id'))->initWechat();
$oauth = $app->oauth;
// 获取 OAuth 授权结果用户信息
$user = $oauth->user();
... ... @@ -183,6 +182,7 @@ class Wechat extends Api
$save['status'] = 'normal';
$save['jointime'] = $save['prevtime'] = $save['logintime'] = time();
$save['loginip'] = $save['joinip'] = request()->ip();
$save['store_id'] =request()->param('store_id');
$w['openid'] = $openid;
$user = Db::name('user')->where($w)->find();
//存在更新否则新增
... ... @@ -298,16 +298,15 @@ class Wechat extends Api
if(empty($my_user_id)){return $this->error('用户信息错误');}
$o_w["order_no"] = $order_no;
$order_info = Db::name('verification_order')->where($o_w)->find();
$user_id = $order_info['user_id'];
$userInfo = Db::name('user')->where(['id'=>$user_id])->find();
$out_trade_no = $order_no;
$o_w["order_no"] = $out_trade_no;
$order_info = Db::name('verification_order')->where($o_w)->find();
$total_fee = $order_info['price'] * 100;
//测试支付
$total_fee = mt_rand(1,10);//测试支付1分钱
//测试结束
$app = WehcatModule::getInstance()->initWechatPay();
$app = WehcatModule::getInstance($order_info['verification_store_id'])->initWechatPay();
$result = $app->order->unify([
'body' => '优惠券购买',
'out_trade_no' => $out_trade_no,
... ... @@ -334,7 +333,7 @@ class Wechat extends Api
{"appid":"wx1c3cc5b4e2006be2","bank_type":"OTHERS","cash_fee":"10","fee_type":"CNY","is_subscribe":"Y","mch_id":"1609190540","nonce_str":"6477162663358","openid":"o5OQw6LSZr1gGhXWeYutDwjsu7UY","out_trade_no":"168552605462002","result_code":"SUCCESS","return_code":"SUCCESS","sign":"B3148E770FAEC4F6B6B0B40718D314DA","time_end":"20230531174105","total_fee":"10","trade_type":"JSAPI","transaction_id":"4200001852202305311195060106"}
*/
public function notify(){
$app = WehcatModule::getInstance()->initWechatPay();
$xml = file_get_contents("php://input");
$xmljson= json_encode(simplexml_load_string($xml, 'SimplexmlElement', LIBXML_NOCDATA ));//将对象转换个JSON
... ... @@ -537,7 +536,7 @@ class Wechat extends Api
$user_info = Db::name('user')->where(['id'=>$pid])->find();
$total_amount = $verification_store['commission'] * 100;
//$total_amount = 100;
$app = WehcatModule::getInstance()->initWechatPay();
$app = WehcatModule::getInstance($verification_order['verification_store_id'])->initWechatPay();
$mch_billno=time().rand(10000,99999);
$result = $app->redpack->sendNormal([
'mch_billno' => $mch_billno,
... ...
... ... @@ -2,7 +2,7 @@
namespace app\server;
use EasyWeChat\Factory;
use think\facade\Db;
/**
* easyWechat 插件
... ... @@ -14,7 +14,7 @@ class Wechat {
static public $app = null;
static private $appid= '';
static private $appsecret= '';
static private $config= [];
static private $inc = null;
function __construct(){
... ... @@ -22,8 +22,11 @@ class Wechat {
}
//静态函数
static public function getInstance(){
static public function getInstance($store_id){
if(self::$inc == null){
$storeInfo = Db::name('verification_store')->where(['id'=>$store_id])->find();
self::$appid = $storeInfo['appId'];
self::$appsecret = $storeInfo['appSecret'];
self::$inc = new self();
}
return self::$inc;
... ... @@ -31,8 +34,8 @@ class Wechat {
//初始化 easywechat app
static public function initWechat(){
$appid= config("site.appid");
$appsecret= config("site.appsecret");
$appid= self::$appid;
$appsecret= self::$appsecret;
//easyWechat配置
$config = [
'app_id' => $appid,
... ... @@ -47,7 +50,7 @@ class Wechat {
//初始化 jssdk支付
static public function initWechatPay(){
//测试公众号
$appid= config("site.appid");
$appid= self::$appid;
$mch_id = config("site.pay_mch_id");
$pay_key = config("site.pay_key");;
$notify_url = 'https://coupon.xp.yn.cn'.url('/api/v1/wechat/notify');
... ...