File tree Expand file tree Collapse file tree 3 files changed +24
-7
lines changed Expand file tree Collapse file tree 3 files changed +24
-7
lines changed Original file line number Diff line number Diff line change 99 Param ,
1010 Body ,
1111 Controller ,
12- HttpCode ,
1312 HttpStatus ,
1413} from '@nestjs/common' ;
1514import { AppException } from 'omniboxd/common/exceptions/app.exception' ;
@@ -50,7 +49,6 @@ export class WeixinController {
5049
5150 @Public ( )
5251 @Post ( 'callback' )
53- @HttpCode ( 204 ) // Return 204 No Content on success as per WeChat Pay V3 API docs
5452 callback ( @Body ( ) body : WeixinCallbackBody ) {
5553 return this . weixinService . callback ( body ) ;
5654 }
Original file line number Diff line number Diff line change @@ -144,6 +144,7 @@ export class WeixinService {
144144 }
145145
146146 callback ( body : WeixinCallbackBody ) {
147+ throw new Error ( JSON . stringify ( body ) ) ;
147148 try {
148149 // Decrypt the callback data
149150 // Note: wechatpay-node-v3 library handles signature verification internally
@@ -195,8 +196,6 @@ export class WeixinService {
195196 } catch ( error ) {
196197 console . log ( body , error ) ;
197198
198- // If decryption fails (e.g., signature verification failed),
199- // throw an exception to return 4XX/5XX status code with error response
200199 throw new AppException (
201200 error . message ,
202201 'SIGNATURE_VERIFICATION_FAILED' ,
@@ -248,8 +247,16 @@ export class WeixinService {
248247 await this . ordersService . close ( order . orderNo ) ;
249248 }
250249
251- const lastOrder : any = await this . ordersService . findById ( userId , orderId ) ;
252- lastOrder . response = response ;
253- return lastOrder ;
250+ if ( wechatData . payer && wechatData . payer . openid ) {
251+ await this . userService . updateUserBindingWhenMetadataEmpty (
252+ userId ,
253+ 'wechat' ,
254+ {
255+ openid : wechatData . payer . openid ,
256+ } ,
257+ ) ;
258+ }
259+
260+ return await this . ordersService . findById ( userId , orderId ) ;
254261 }
255262}
Original file line number Diff line number Diff line change @@ -182,6 +182,18 @@ export class UserService {
182182 } ) ;
183183 }
184184
185+ async updateUserBindingWhenMetadataEmpty (
186+ userId : string ,
187+ loginType : string ,
188+ metadata : Record < string , any > ,
189+ ) {
190+ const userBinding = await this . findUserBinding ( userId , loginType ) ;
191+ if ( userBinding && ! userBinding . metadata ) {
192+ userBinding . metadata = metadata ;
193+ await this . userBindingRepository . save ( userBinding ) ;
194+ }
195+ }
196+
185197 async updateBinding ( oldUnionid : string , newUnionid : string ) {
186198 // Unbind the associated new account
187199 const existBinding = await this . userBindingRepository . findOne ( {
You can’t perform that action at this time.
0 commit comments